Merge branch 'master' of git://github.com/flosch/mongoengine into v0.4
Conflicts: tests/fields.py
This commit is contained in:
commit
40eb23a97a
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ docs/_build
|
||||
build/
|
||||
dist/
|
||||
mongoengine.egg-info/
|
||||
env/
|
@ -410,8 +410,6 @@ class BaseDocument(object):
|
||||
value = getattr(self, field_name, None)
|
||||
if value is not None:
|
||||
data[field.db_field] = field.to_mongo(value)
|
||||
else:
|
||||
data[field.db_field] = None
|
||||
# Only add _cls and _types if allow_inheritance is not False
|
||||
if not (hasattr(self, '_meta') and
|
||||
self._meta.get('allow_inheritance', True) == False):
|
||||
@ -454,7 +452,8 @@ class BaseDocument(object):
|
||||
for field_name, field in cls._fields.items():
|
||||
if field.db_field in data:
|
||||
value = data[field.db_field]
|
||||
data[field_name] = value if value is None else field.to_python(value)
|
||||
data[field_name] = (value if value is None
|
||||
else field.to_python(value))
|
||||
|
||||
obj = cls(**data)
|
||||
obj._present_fields = present_fields
|
||||
|
@ -66,6 +66,9 @@ class StringField(BaseField):
|
||||
regex = r'%s$'
|
||||
elif op == 'exact':
|
||||
regex = r'^%s$'
|
||||
|
||||
# escape unsafe characters which could lead to a re.error
|
||||
value = re.escape(value)
|
||||
value = re.compile(regex % value, flags)
|
||||
return value
|
||||
|
||||
|
@ -135,7 +135,6 @@ class Q(object):
|
||||
|
||||
# Handle DBRef
|
||||
if isinstance(value, pymongo.dbref.DBRef):
|
||||
# this.created_user.$id == "4c4c56f8cc1831418c000000"
|
||||
op_js = '(this.%(field)s.$id == "%(id)s" &&'\
|
||||
' this.%(field)s.$ref == "%(ref)s")' % {
|
||||
'field': key,
|
||||
@ -240,6 +239,10 @@ class QuerySet(object):
|
||||
"""
|
||||
return self.__call__(*q_objs, **query)
|
||||
|
||||
def all(self):
|
||||
"""Returns all documents."""
|
||||
return self.__call__()
|
||||
|
||||
@property
|
||||
def _collection(self):
|
||||
"""Property that returns the collection object. This allows us to
|
||||
@ -667,11 +670,13 @@ class QuerySet(object):
|
||||
"""
|
||||
key_list = []
|
||||
for key in keys:
|
||||
if not key: continue
|
||||
direction = pymongo.ASCENDING
|
||||
if key[0] == '-':
|
||||
direction = pymongo.DESCENDING
|
||||
if key[0] in ('-', '+'):
|
||||
key = key[1:]
|
||||
key = key.replace('__', '.')
|
||||
key_list.append((key, direction))
|
||||
|
||||
self._ordering = key_list
|
||||
|
@ -675,6 +675,11 @@ class FieldTest(unittest.TestCase):
|
||||
StreamFile.drop_collection()
|
||||
SetFile.drop_collection()
|
||||
|
||||
# Make sure FileField is optional and not required
|
||||
class DemoFile(Document):
|
||||
file = FileField()
|
||||
d = DemoFile.objects.create()
|
||||
|
||||
def test_geo_indexes(self):
|
||||
"""Ensure that indexes are created automatically for GeoPointFields.
|
||||
"""
|
||||
@ -694,7 +699,7 @@ class FieldTest(unittest.TestCase):
|
||||
Event.drop_collection()
|
||||
|
||||
def test_ensure_unique_default_instances(self):
|
||||
"""Ensure that every document has it's own unique default instance."""
|
||||
"""Ensure that every field has it's own unique default instance."""
|
||||
class D(Document):
|
||||
data = DictField()
|
||||
data2 = DictField(default=lambda: {})
|
||||
|
@ -289,6 +289,13 @@ class QuerySetTest(unittest.TestCase):
|
||||
obj = self.Person.objects(Q(name__iexact='gUIDO VAN rOSSU')).first()
|
||||
self.assertEqual(obj, None)
|
||||
|
||||
# Test unsafe expressions
|
||||
person = self.Person(name='Guido van Rossum [.\'Geek\']')
|
||||
person.save()
|
||||
|
||||
obj = self.Person.objects(Q(name__icontains='[.\'Geek')).first()
|
||||
self.assertEqual(obj, person)
|
||||
|
||||
def test_filter_chaining(self):
|
||||
"""Ensure filters can be chained together.
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user