def html_json(values): content = serializer.encode(values) try: content = content.encode("unicode-escape") except LookupError: content = content.encode("string-escape") return Markup(content)
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)
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)
def as_json(values): content = serializer.encode(values) return Markup(content)
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)
def test_time(self): now = time() value = serializer.encode({'now': now}) self.assertTrue(value)
def test_date(self): now = date.today() value = serializer.encode({'now': now}) self.assertTrue(value)
def test_datetime(self): now = datetime.now() value = serializer.encode({'now': now}) self.assertTrue(value)