Browse files

temporary fix. This implementation is just wrong though, we need to go

for a serialisation based on rules using pattern and types of objects.
  • Loading branch information...
1 parent dab67f9 commit e19da4af32bebed2d46ac36f024315f55db5cd7f benoitc committed Dec 6, 2010
Showing with 16 additions and 10 deletions.
  1. +16 −10 webmachine/helpers/
26 webmachine/helpers/
@@ -78,22 +78,24 @@ def _to_python(self, value):
def dict_to_emittable(value, fields=None, exclude=None):
""" convert a dict to json """
- return dict([(k, value_to_emittable(v)) for k, v in value.iteritems()])
+ return dict([(k, value_to_emittable(v, fields=fields,
+ exclude=exclude)) for k, v in value.iteritems()])
def list_to_emittable(value, fields=None, exclude=None):
""" convert a list to json """
- return [value_to_emittable(item) for item in value]
+ return [value_to_emittable(item, fields=fields, exclude=exclude) for item in value]
def relm_to_emittable(value):
return value_to_emittable(value.all())
-def fk_to_emittable(value, field):
+def fk_to_emittable(value, field, fields=None, exclude=None):
return value_to_emittable(getattr(value,
-def m2m_to_emittable(value, field):
- return [model_to_emittable(m) for m in getattr(value, ]
+def m2m_to_emittable(value, field, fields=None, exclude=None):
+ return [model_to_emittable(m, fields=fields, exclude=exclude) \
+ for m in getattr(value, ]
def qs_to_emittable(value, fields=None, exclude=None):
return [value_to_emittable(v, fields=fields, exclude=exclude) for v in value]
@@ -116,22 +118,25 @@ def model_to_emittable(instance, fields=None, exclude=None):
fields_iter = iter(meta.local_fields + meta.virtual_fields + meta.many_to_many)
for f in fields_iter:
value = None
- if fields and not in fields:
+ print
+ if fields is not None and not in fields:
- if exclude and in exclude:
+ if exclude is not None and in exclude:
if f in meta.many_to_many:
if f.serialize:
- value = m2m_to_emittable(instance, f)
+ value = m2m_to_emittable(instance, f, fields=fields,
+ exclude=exclude)
if f.serialize:
if not f.rel:
value = value_to_emittable(getattr(instance,
- f.attname))
+ f.attname), fields=fields, exclude=exclude)
- value = fk_to_emittable(instance, f)
+ value = fk_to_emittable(instance, f,
+ fields=fields, exclude=exclude)
if value is None:
@@ -146,6 +151,7 @@ def value_to_emittable(value, fields=None, exclude=None):
For Dates we use ISO 8601. Decimal are converted to string.
if isinstance(value, QuerySet):
+ print "ici %s" % exclude
value = qs_to_emittable(value, fields=fields, exclude=exclude)
elif isinstance(value, datetime.datetime):
value = value.replace(microsecond=0).isoformat() + 'Z'

0 comments on commit e19da4a

Please sign in to comment.