Commits

imbolc  committed de46bc6

add 'text', 'html' to view(render_to) and render(to) | set default Response content_type to html

  • Participants
  • Parent commits 53bb8b5

Comments (0)

Files changed (4)

File pysi/decorators.py

 def view(url_or_code, render_to=None, **response_kwargs):
     '''
     *url_or_code - урл для роутинга или код http-ошибки
-    *render_to   - шаблон или 'json'
+    *render_to   - шаблон или 'json', 'text', 'html'
     '''
     def decorator(func):
         urlname = _get_urlname(func)

File pysi/template.py

         data = _json_dumps()(context)
         if 'callback' in rq.GET:
             data = '%s(%s)' % (rq.GET['callback'], data)  # jsonp
-            ct = 'application/x-javascript'
+            content_type = 'application/x-javascript'
         else:
-            ct = 'application/json'
-        return wsgi.Response(data, content_type=ct, **response_kwargs)
-    return wsgi.Response(
-        render_to_string(rq, to, context), **response_kwargs)
+            content_type = 'application/json'
+    elif to == 'text':
+        data = unicode(context)
+        content_type = 'text/plain'
+    elif to == 'html':
+        data = unicode(context)
+        content_type = 'text/html'
+    else:
+        data = render_to_string(rq, to, context)
+        content_type = 'text/html'
+    if 'content_type' not in response_kwargs:
+        response_kwargs['content_type'] = content_type
+    return wsgi.Response(data, **response_kwargs)
 
 @cached_function
 def _json_dumps():

File pysi/wsgi.py

                 middleware(rq)
             res = self.routing(rq)
             if not isinstance(res, Response):
-                res = Response(unicode(res), content_type='text/plain')
+                res = Response(unicode(res), content_type='text/html')
             for middleware in self.response_middlewares:
                 middleware(rq, res)
         except Response, e:
 import os
 from setuptools import setup
 
-VERSION = '0.8.4'
+VERSION = '0.8.5'
 PACKAGE = 'pysi'
 
 if __name__ == '__main__':