示例#1
0
 def render_json(self, request, context, template_name):
     context = simplify_value(context)
     resolved = resolve(request.path)
     context['view_name'] = '%s:%s' % (':'.join(
         resolved.namespaces), resolved.url_name)
     return HttpResponse(simplejson.dumps(context),
                         mimetype="application/json")
示例#2
0
 def render_json(self, request, context, template_name):
     context = simplify_value(context)
     resolved = resolve(request.path)
     context['view_name'] = '%s:%s' % (
         self.conf.application_name.split('.')[-1], resolved.url_name)
     
     # Include CSRF token, as templates don't get rendered csrf_token is
     # never called which breaks CSRF for apps written against the JSON API
     get_token(request)
     
     return HttpResponse(simplejson.dumps(context),
                         mimetype="application/json")
示例#3
0
    def render_json(self, request, context, template_name):
        context = simplify_value(context)
        resolved = resolve(request.path)
        context['view_name'] = '%s:%s' % (
            self.conf.application_name.split('.')[-1], resolved.url_name)

        # Include CSRF token, as templates don't get rendered csrf_token is
        # never called which breaks CSRF for apps written against the JSON API
        get_token(request)

        return HttpResponse(simplejson.dumps(context),
                            mimetype="application/json")
示例#4
0
 def render_yaml(self, request, context, template_name):
     import yaml
     context = simplify_value(context)
     return HttpResponse(yaml.safe_dump(context),
                         mimetype="application/x-yaml")
示例#5
0
 def render_xml(self, request, context, template_name):
     context = simplify_value(context)
     return HttpResponse(
         etree.tostring(serialize_to_xml(context), encoding='UTF-8'),
         mimetype="application/xml")
示例#6
0
 def render_js(self, request, context, template_name):
     callback = request.GET.get('callback',
                                request.GET.get('jsonp', 'callback'))
     content = simplejson.dumps(simplify_value(context))
     content = "%s(%s);" % (callback, content)
     return HttpResponse(content, mimetype="application/javascript")
示例#7
0
 def render_json(self, request, context, template_name):
     context = simplify_value(context)
     return HttpResponse(simplejson.dumps(context),
                         mimetype="application/json")
示例#8
0
 def render_json(self, request, context, template_name):
     context = simplify_value(context)
     resolved = resolve(request.path)
     context['view_name'] = '%s:%s' % (':'.join(resolved.namespaces), resolved.url_name)
     return HttpResponse(simplejson.dumps(context),
                         mimetype="application/json")
示例#9
0
 def render_yaml(self, request, context, template_name):
     import yaml
     context = simplify_value(context)
     return HttpResponse(yaml.safe_dump(context),
                         mimetype="application/x-yaml")
示例#10
0
 def render_xml(self, request, context, template_name):
     context = simplify_value(context)
     return HttpResponse(etree.tostring(serialize_to_xml(context),
                                        encoding='UTF-8'),
                         mimetype="application/xml")
示例#11
0
 def render_js(self, request, context, template_name):
     callback = request.GET.get('callback',
                                request.GET.get('jsonp', 'callback'))
     content = simplejson.dumps(simplify_value(context))
     content = "%s(%s);" % (callback, content)
     return HttpResponse(content, mimetype="application/javascript")