Commits

Luke Plant committed b834c8a

Made JsonResponse subcless HttpResponse

Used subclassing instead of encapsulation, to allow cache decorators to
be used on view functions.

Comments (0)

Files changed (1)

lukeplant_me_uk/bibleverses/web/cgi-bin/lib/bibleverses/views.py

 MSG_EMAIL_NOT_FOUND = 4
 MSG_PASSWORD_INCORRECT = 5
 
-class JsonResponse(object):
+class JsonResponse(HttpResponse):
     def __init__(self, obj):
-        self.obj = obj
-
-    def __str__(self):
-        resp = HttpResponse()
-        resp.content = simplejson.dumps(self.obj)
-        resp.content_type = "text/javascript"
-        return str(resp)
+        super(JsonResponse, self).__init__()
+        self.content = simplejson.dumps(obj)
+        self.content_type = "text/javascript"
 
 def success(**kwargs):
     kwargs['success'] = True
 #############################################
 
 urls = [
-    ('^/register/$', catch_all(register)),
-    ('^/login/$', catch_all(login)),
-    ('^/verses/$', catch_all(verses)),
-    ('^/addverse/$', catch_all(addverse)),
-    ('^/removeverse/$', catch_all(removeverse)),
-    ('^/debug/$', catch_all(debug)),
+    ('^/register/$',    register),
+    ('^/login/$',       login),
+    ('^/verses/$',      verses),
+    ('^/addverse/$',    addverse),
+    ('^/removeverse/$', removeverse),
+    ('^/debug/$',       debug),
 #    ('^/initdb/$', catch_all(initdb)),
 #    ('^/dropdb/$', catch_all(dropdb)),
 ]
 
+urls = [(regex, catch_all(f)) for regex, f in urls]
+
 def main():
     dispatch(urls)