Anonymous avatar Anonymous committed 9ba4a23

Added per request fields support.
Patched emitter to pass the fields attribute recursively.

Comments (0)

Files changed (2)

piston/emitters.py

             elif isinstance(thing, (tuple, list, set)):
                 ret = _list(thing)
             elif isinstance(thing, dict):
-                ret = _dict(thing)
+                ret = _dict(thing, fields)
             elif isinstance(thing, decimal.Decimal):
                 ret = str(thing)
             elif isinstance(thing, Model):
             """
             return [ _any(v) for v in data ]
             
-        def _dict(data):
+        def _dict(data, fields):
             """
             Dictionaries.
             """
-            return dict([ (k, _any(v)) for k, v in data.iteritems() ])
+            return dict([ (k, _any(v, fields)) for k, v in data.iteritems() ])
             
         # Kickstart the seralizin'.
         return _any(self.data, self.fields)

piston/resource.py

                 raise
 
         emitter, ct = Emitter.get(em_format)
-        fields = handler.fields
-        if hasattr(handler, 'list_fields') and (
-                isinstance(result, list) or isinstance(result, QuerySet)):
-            fields = handler.list_fields
+        try:
+            result, fields = result
+        except ValueError:
+            fields = handler.fields
+            if hasattr(handler, 'list_fields') and (
+                    isinstance(result, list) or isinstance(result, QuerySet)):
+                fields = handler.list_fields
 
         srl = emitter(result, typemapper, handler, fields, anonymous)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.