示例#1
0
def html_json(values):
    content = serializer.encode(values)
    try:
        content = content.encode("unicode-escape")
    except LookupError:
        content = content.encode("string-escape")
    return Markup(content)
示例#2
0
 def test_page(self):
     total = 200
     object_list = list(range(total))
     num = 3
     pg = Paginator(object_list, per_page=10).page(num)
     result = json.loads(serializer.encode(pg))
     self.assertEqual(result['total'], total)
     self.assertEqual(result['per_page'], 10)
     self.assertEqual(result['start_index'], 21)
     self.assertEqual(result['end_index'], 30)
     self.assertEqual(result['index'], num)
示例#3
0
 def render_to_response(self, payload, **kwargs):
     content = serializer.encode(payload, serializers=self.get_serializers())
     kwargs.setdefault('status', 200)
     kwargs.setdefault('content_type', 'application/json')
     return HttpResponse(content, **kwargs)
示例#4
0
def as_json(values):
    content = serializer.encode(values)
    return Markup(content)
示例#5
0
文件: ui.py 项目: vivsh/django-ginger
def as_json(values):
    content = serializer.encode(values)
    return Markup(content)
示例#6
0
 def test_dummy_class(self):
     obj = DummyClass()
     self.assertRaises(TypeError, lambda : serializer.encode(obj))
     value = serializer.encode(obj, serializers={DummyClass: lambda o: o.name})
     self.assertEqual(value, '"hello"', value)
示例#7
0
 def test_time(self):
     now = time()
     value = serializer.encode({'now': now})
     self.assertTrue(value)
示例#8
0
 def test_date(self):
     now = date.today()
     value = serializer.encode({'now': now})
     self.assertTrue(value)
示例#9
0
 def test_datetime(self):
     now = datetime.now()
     value = serializer.encode({'now': now})
     self.assertTrue(value)
示例#10
0
 def render_to_response(self, payload, **kwargs):
     content = serializer.encode(payload,
                                 serializers=self.get_serializers())
     kwargs.setdefault('status', 200)
     kwargs.setdefault('content_type', 'application/json')
     return HttpResponse(content, **kwargs)