Пример #1
0
    def repr_model_sequence(self, inst, p, cycle):
        '''
        Format a sequence of models.
        '''
        if cycle:
            raise NotImplementedError('Cycle detected.')

        if self.use_dict_for_model_output:
            p.pretty([m for m in inst])
        else:
            p.pretty(json.loads(django_serialize('json', inst)))
Пример #2
0
    def repr_model(self, inst, p, cycle):
        '''
        Format Django model nicely
        '''
        if cycle:
            raise NotImplementedError('Cycle detected.')

        if self.use_dict_for_model_output:
            p.pretty(inst.__dict__)
        else:
            inst, = json.loads(django_serialize('json', [inst]))
            p.pretty(inst)
Пример #3
0
 def deep_serialize(obj):
     if type(obj) == dict:
         for key, value in obj.iteritems():
             obj[key] = deep_serialize(value)
         return obj
     elif hasattr(obj, '__iter__'):
         result = []
         for item in obj:
             result.append(deep_serialize(item))
         return result
     elif isinstance(obj, Model) and hasattr(obj, 'dictify'):
         return obj.dictify()
     elif type(obj) in (unicode, str, int, float):
         return obj
     elif type(obj) == datetime.datetime:
         return str(obj)
     else:
         return django_serialize('python', [obj])[0]
Пример #4
0
 def render(self, context):
   obj = self.project.resolve(context)
   if obj:
     context[self.varname] = django_serialize('json', [obj])
   return ""
def attendanceSerializer(data):
    return django_serialize('json', list(data))