Permalink
Browse files

bug fix of to_json for recursive embedding && small change to handle …

…required=True for embedded field
  • Loading branch information...
1 parent 5400367 commit eeb5cfd400e869cabcbaffa7b70d499a50975661 @tomwaits committed Jul 20, 2011
Showing with 10 additions and 4 deletions.
  1. +3 −2 dictshield/base.py
  2. +6 −1 dictshield/document.py
  3. +1 −1 dictshield/fields.py
View
@@ -119,7 +119,8 @@ def for_python(self, value):
def for_json(self, value):
"""Convert a DictShield type into a value safe for JSON encoding
"""
- return self.for_python(value)
+ return json.dumps(value)
+# return self.for_json(value)
def validate(self, value):
"""Perform validation on a value.
@@ -448,7 +449,7 @@ def to_json(self):
#data = self.to_python()
fun = lambda f, v: f.for_json(v)
data = self._to_fields(fun)
- return json.dumps(data)
+ return data
@classmethod
def _from_son(cls, son): # TODO rename to json
@@ -182,7 +182,12 @@ def handle_exception(e):
continue
if fun(k, v):
- datum = values[k]
+ try:
+ datum = values[k]
+ except KeyError:
+ e = DictPunch('Required Embedded Field Not Found:', k, v)
+ handle_exception(e)
+ continue
# if datum is None, skip
if datum is None:
continue
@@ -415,7 +415,7 @@ def for_python(self, value):
def for_json(self, value):
data = self._to_instance(value)
- return data.to_python()
+ return data.to_json()
def validate(self, value):
"""Make sure that the document instance is an instance of the

0 comments on commit eeb5cfd

Please sign in to comment.