[Checkins] SVN: grok/trunk/ JSON views now report a Content-type: text/json

Michael Haubenwallner michael at d2m.at
Mon May 18 04:20:02 EDT 2009


Log message for revision 100062:
  JSON views now report a Content-type: text/json

Changed:
  U   grok/trunk/CHANGES.txt
  U   grok/trunk/src/grok/components.py
  A   grok/trunk/src/grok/ftests/json/
  A   grok/trunk/src/grok/ftests/json/__init__.py
  A   grok/trunk/src/grok/ftests/json/json.py
  U   grok/trunk/src/grok/ftests/test_grok_functional.py

-=-
Modified: grok/trunk/CHANGES.txt
===================================================================
--- grok/trunk/CHANGES.txt	2009-05-18 08:14:35 UTC (rev 100061)
+++ grok/trunk/CHANGES.txt	2009-05-18 08:20:01 UTC (rev 100062)
@@ -4,10 +4,18 @@
 1.0b1 (unreleased)
 ==================
 
-- Import zope.app.container interfaces from their actual definition not from a
+* Import zope.app.container interfaces from their actual definition not from a
   re-import.
 
+* JSON views now report a Content-type: text/json. See
+  https://bugs.launchpad.net/bugs/362902
 
+Bug fixes
+---------
+
+* Pinned zope.container (wait for grokcore.view to take over)
+
+
 1.0a3 (2009-04-10)
 ==================
 

Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py	2009-05-18 08:14:35 UTC (rev 100061)
+++ grok/trunk/src/grok/components.py	2009-05-18 08:20:01 UTC (rev 100062)
@@ -384,6 +384,7 @@
         view_name = self.__view_name__
         method = getattr(self, view_name)
         method_result = mapply(method, (), self.request)
+        self.request.response.setHeader('content-type', 'text/json')
         return simplejson.dumps(method_result)
 
 

Added: grok/trunk/src/grok/ftests/json/__init__.py
===================================================================
--- grok/trunk/src/grok/ftests/json/__init__.py	                        (rev 0)
+++ grok/trunk/src/grok/ftests/json/__init__.py	2009-05-18 08:20:01 UTC (rev 100062)
@@ -0,0 +1,2 @@
+#
+

Added: grok/trunk/src/grok/ftests/json/json.py
===================================================================
--- grok/trunk/src/grok/ftests/json/json.py	                        (rev 0)
+++ grok/trunk/src/grok/ftests/json/json.py	2009-05-18 08:20:01 UTC (rev 100062)
@@ -0,0 +1,22 @@
+"""
+  >>> getRootFolder()['cave'] = cave = Cave()
+
+JSON views answer a special content-type::
+
+  >>> print http('GET /cave/show HTTP/1.1')
+  HTTP/1. 200 Ok
+  Content-Length: 17
+  Content-Type: text/json
+  <BLANKLINE>
+  "A Cavemans cave"
+
+"""
+
+import grok
+
+class Cave(grok.Model):
+    pass
+
+class CaveJSON(grok.JSON):
+    def show(self):
+        return 'A Cavemans cave'
\ No newline at end of file

Modified: grok/trunk/src/grok/ftests/test_grok_functional.py
===================================================================
--- grok/trunk/src/grok/ftests/test_grok_functional.py	2009-05-18 08:14:35 UTC (rev 100061)
+++ grok/trunk/src/grok/ftests/test_grok_functional.py	2009-05-18 08:20:01 UTC (rev 100062)
@@ -71,7 +71,7 @@
 def test_suite():
     suite = unittest.TestSuite()
     for name in ['xmlrpc', 'traversal', 'form', 'url', 'security',
-                 'utility', 'catalog', 'site', 'rest', 'viewlet']:
+                 'utility', 'catalog', 'site', 'rest', 'viewlet','json']:
         suite.addTest(suiteFromPackage(name))
     return suite
 



More information about the Checkins mailing list