Commits

Matthew Schinckel committed fe3e7dd

Added (rudimentary) support for collection+json

Comments (0)

Files changed (2)

repose/serializers/__init__.py

-import json, post_encoded, html, xml_serialiser, yaml
+import json, post_encoded, html, xml_serialiser, yaml, collection_json
 from base import get_incoming_content_type, get_preferred_content_type
 from registry import register, unregister, get_serializer
 

repose/serializers/collection_json.py

+"""
+application/vnd.collection+json
+"""
+from django.conf import settings
+from django.utils import simplejson
+
+from base import BaseSerializer, pre_serialize_form
+from json import default
+from registry import register
+
+class CollectionJSON(BaseSerializer):
+    content_type = "application/vnd.collection+json"
+    
+    def serialize(self, form=None, request=None, response=None, **kwargs):
+        data = pre_serialize_form(form)
+        kwargs.pop('template_name', None)
+        if settings.DEBUG:
+            kwargs['indent'] = 2
+        
+        data = {
+            "collection": {
+                "href": "...",
+                "links": [],
+                "items": data,
+                "queries": [],
+                "template": [],
+                "error": {}
+            }
+        }
+        
+        return simplejson.dumps(data, default=default, **kwargs)
+        
+
+register(CollectionJSON())
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.