Fix MapField in order to handle unicode keys.
This commit is contained in:
parent
a20d40618f
commit
4650e5e8fb
@ -1,5 +1,7 @@
|
|||||||
from bson import DBRef, SON
|
from bson import DBRef, SON
|
||||||
|
|
||||||
|
from mongoengine.python_support import txt_type
|
||||||
|
|
||||||
from base import (
|
from base import (
|
||||||
BaseDict, BaseList, EmbeddedDocumentList,
|
BaseDict, BaseList, EmbeddedDocumentList,
|
||||||
TopLevelDocumentMetaclass, get_document
|
TopLevelDocumentMetaclass, get_document
|
||||||
@ -226,7 +228,7 @@ class DeReference(object):
|
|||||||
data[k]._data[field_name] = self.object_map.get(
|
data[k]._data[field_name] = self.object_map.get(
|
||||||
(v['_ref'].collection, v['_ref'].id), v)
|
(v['_ref'].collection, v['_ref'].id), v)
|
||||||
elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
|
elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
|
||||||
item_name = "{0}.{1}.{2}".format(name, k, field_name)
|
item_name = txt_type("{0}.{1}.{2}").format(name, k, field_name)
|
||||||
data[k]._data[field_name] = self._attach_objects(v, depth, instance=instance, name=item_name)
|
data[k]._data[field_name] = self._attach_objects(v, depth, instance=instance, name=item_name)
|
||||||
elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
|
elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
|
||||||
item_name = '%s.%s' % (name, k) if name else name
|
item_name = '%s.%s' % (name, k) if name else name
|
||||||
|
@ -1515,6 +1515,29 @@ class FieldTest(unittest.TestCase):
|
|||||||
actions__friends__operation='drink',
|
actions__friends__operation='drink',
|
||||||
actions__friends__object='beer').count())
|
actions__friends__object='beer').count())
|
||||||
|
|
||||||
|
def test_map_field_unicode(self):
|
||||||
|
|
||||||
|
class Info(EmbeddedDocument):
|
||||||
|
description = StringField()
|
||||||
|
value_list = ListField(field=StringField())
|
||||||
|
|
||||||
|
class BlogPost(Document):
|
||||||
|
info_dict = MapField(field=EmbeddedDocumentField(Info))
|
||||||
|
|
||||||
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
|
tree = BlogPost(info_dict={
|
||||||
|
u"éééé": {
|
||||||
|
'description': u"VALUE: éééé"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
tree.save()
|
||||||
|
|
||||||
|
self.assertEqual(BlogPost.objects.get(id=tree.id).info_dict[u"éééé"].description, u"VALUE: éééé")
|
||||||
|
|
||||||
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
def test_embedded_db_field(self):
|
def test_embedded_db_field(self):
|
||||||
|
|
||||||
class Embedded(EmbeddedDocument):
|
class Embedded(EmbeddedDocument):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user