Merge branch 'master' into support_position_in_push
This commit is contained in:
commit
7311895894
1
AUTHORS
1
AUTHORS
@ -243,4 +243,5 @@ that much better:
|
|||||||
* Victor Varvaryuk
|
* Victor Varvaryuk
|
||||||
* Stanislav Kaledin (https://github.com/sallyruthstruik)
|
* Stanislav Kaledin (https://github.com/sallyruthstruik)
|
||||||
* Dmitry Yantsen (https://github.com/mrTable)
|
* Dmitry Yantsen (https://github.com/mrTable)
|
||||||
|
* Renjianxin (https://github.com/Davidrjx)
|
||||||
* Erdenezul Batmunkh (https://github.com/erdenezul)
|
* Erdenezul Batmunkh (https://github.com/erdenezul)
|
@ -146,13 +146,14 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
|
|||||||
raise MongoEngineConnectionError(msg)
|
raise MongoEngineConnectionError(msg)
|
||||||
|
|
||||||
def _clean_settings(settings_dict):
|
def _clean_settings(settings_dict):
|
||||||
irrelevant_fields = set([
|
# set literal more efficient than calling set function
|
||||||
'name', 'username', 'password', 'authentication_source',
|
irrelevant_fields_set = {
|
||||||
'authentication_mechanism'
|
'name', 'username', 'password',
|
||||||
])
|
'authentication_source', 'authentication_mechanism'
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
k: v for k, v in settings_dict.items()
|
k: v for k, v in settings_dict.items()
|
||||||
if k not in irrelevant_fields
|
if k not in irrelevant_fields_set
|
||||||
}
|
}
|
||||||
|
|
||||||
# Retrieve a copy of the connection settings associated with the requested
|
# Retrieve a copy of the connection settings associated with the requested
|
||||||
|
@ -1722,25 +1722,33 @@ class BaseQuerySet(object):
|
|||||||
return frequencies
|
return frequencies
|
||||||
|
|
||||||
def _fields_to_dbfields(self, fields):
|
def _fields_to_dbfields(self, fields):
|
||||||
"""Translate fields paths to its db equivalents"""
|
"""Translate fields' paths to their db equivalents."""
|
||||||
ret = []
|
|
||||||
subclasses = []
|
subclasses = []
|
||||||
document = self._document
|
if self._document._meta['allow_inheritance']:
|
||||||
if document._meta['allow_inheritance']:
|
|
||||||
subclasses = [get_document(x)
|
subclasses = [get_document(x)
|
||||||
for x in document._subclasses][1:]
|
for x in self._document._subclasses][1:]
|
||||||
|
|
||||||
|
db_field_paths = []
|
||||||
for field in fields:
|
for field in fields:
|
||||||
|
field_parts = field.split('.')
|
||||||
try:
|
try:
|
||||||
field = '.'.join(f.db_field for f in
|
field = '.'.join(
|
||||||
document._lookup_field(field.split('.')))
|
f if isinstance(f, six.string_types) else f.db_field
|
||||||
ret.append(field)
|
for f in self._document._lookup_field(field_parts)
|
||||||
|
)
|
||||||
|
db_field_paths.append(field)
|
||||||
except LookUpError as err:
|
except LookUpError as err:
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
|
# If a field path wasn't found on the main document, go
|
||||||
|
# through its subclasses and see if it exists on any of them.
|
||||||
for subdoc in subclasses:
|
for subdoc in subclasses:
|
||||||
try:
|
try:
|
||||||
subfield = '.'.join(f.db_field for f in
|
subfield = '.'.join(
|
||||||
subdoc._lookup_field(field.split('.')))
|
f if isinstance(f, six.string_types) else f.db_field
|
||||||
ret.append(subfield)
|
for f in subdoc._lookup_field(field_parts)
|
||||||
|
)
|
||||||
|
db_field_paths.append(subfield)
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
except LookUpError:
|
except LookUpError:
|
||||||
@ -1748,7 +1756,8 @@ class BaseQuerySet(object):
|
|||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
raise err
|
raise err
|
||||||
return ret
|
|
||||||
|
return db_field_paths
|
||||||
|
|
||||||
def _get_order_by(self, keys):
|
def _get_order_by(self, keys):
|
||||||
"""Given a list of MongoEngine-style sort keys, return a list
|
"""Given a list of MongoEngine-style sort keys, return a list
|
||||||
|
@ -197,14 +197,18 @@ class OnlyExcludeAllTest(unittest.TestCase):
|
|||||||
title = StringField()
|
title = StringField()
|
||||||
text = StringField()
|
text = StringField()
|
||||||
|
|
||||||
|
class VariousData(EmbeddedDocument):
|
||||||
|
some = BooleanField()
|
||||||
|
|
||||||
class BlogPost(Document):
|
class BlogPost(Document):
|
||||||
content = StringField()
|
content = StringField()
|
||||||
author = EmbeddedDocumentField(User)
|
author = EmbeddedDocumentField(User)
|
||||||
comments = ListField(EmbeddedDocumentField(Comment))
|
comments = ListField(EmbeddedDocumentField(Comment))
|
||||||
|
various = MapField(field=EmbeddedDocumentField(VariousData))
|
||||||
|
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
post = BlogPost(content='Had a good coffee today...')
|
post = BlogPost(content='Had a good coffee today...', various={'test_dynamic':{'some': True}})
|
||||||
post.author = User(name='Test User')
|
post.author = User(name='Test User')
|
||||||
post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')]
|
post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')]
|
||||||
post.save()
|
post.save()
|
||||||
@ -215,6 +219,9 @@ class OnlyExcludeAllTest(unittest.TestCase):
|
|||||||
self.assertEqual(obj.author.name, 'Test User')
|
self.assertEqual(obj.author.name, 'Test User')
|
||||||
self.assertEqual(obj.comments, [])
|
self.assertEqual(obj.comments, [])
|
||||||
|
|
||||||
|
obj = BlogPost.objects.only('various.test_dynamic.some').get()
|
||||||
|
self.assertEqual(obj.various["test_dynamic"].some, True)
|
||||||
|
|
||||||
obj = BlogPost.objects.only('content', 'comments.title',).get()
|
obj = BlogPost.objects.only('content', 'comments.title',).get()
|
||||||
self.assertEqual(obj.content, 'Had a good coffee today...')
|
self.assertEqual(obj.content, 'Had a good coffee today...')
|
||||||
self.assertEqual(obj.author, None)
|
self.assertEqual(obj.author, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user