Пример #1
0
    def translate(self, format, response):
        # We catch and return any HttpResponses here for convenience's sake.
        # This really should be the developers responsibility
        if isinstance(response, HttpResponse):
            return response

        emitter, ctype = self.emitter_for_format(format)
        
        if emitter and ctype:
            # Set the content type to text/plain when in debug mode, so that the
            # response will be viewable within the browser.
            if settings.DEBUG:
                ctype = 'text/plain; charset=utf-8'

            ops = {'content_type': ctype}            
            if isinstance(response, EmittableResponse):
                ops.update(response.ops)
                response = response.content
            
            # Deconstruct the response, serializer it, and then create a new
            # HttpResponse with the given options specified.
            response = deconstruct(response)
            return HttpResponse((response), **ops)
        return HttpResponseBadRequest("Cannot to serialize response to '%s' "
            "format specified in request" % format)        
Пример #2
0
 def get_model_data(self, model): 
     return {
         'generated_fields': self.generate_fields(model),
         'meta': [{'key': k, 'value': simplejson.dumps(deconstruct(v),
             cls=DjangoJSONEncoder, ensure_ascii=False)} for k, v in
             self.get_meta(model).items()],
     }
Пример #3
0
 def get_field_data(self):
     #if type(self.field)=="instancemethod":
     if not hasattr(self.field, 'primary_key'):
         return {
                 'comments': self.field.sd_type+" "+self.field.sd_comment,
                 'name': self.field.sd_name,
                 'record': self.get_record(),
                 'js_type': self.field.sd_type,
                 'attributes': {
                     'verbose_name': self.field.sd_verbose_name,
                     'default': self.field.sd_default
                     }
                 }
     elif self.should_render():
         return {
             'comments': '\n\n'.join(self.get_comments()),
             'name': self.get_name(),
             'record': self.get_record(),
             'js_type': self.get_js_type(),
             'attributes': simplejson.dumps(
                 deconstruct(self.get_attributes()),
                 cls = DjangoJSONEncoder,
                 ensure_ascii = False
             )
         }
 def get_field_data(self):
     if self.should_render():
         return {
             'comments': '\n\n'.join(self.get_comments()),
             'name': self.get_name(),
             'record': self.get_record(),
             'js_type': self.get_js_type(),
             'attributes': simplejson.dumps(
                 deconstruct(self.get_attributes()),
                 cls = DjangoJSONEncoder,
                 ensure_ascii = False
             )
         }