Пример #1
0
 def handler(obj):
     try:
         json_handler(obj)
     except Exception:
         if isinstance(obj, SerializableFunction):
             return {'type': 'SerializedFunction', 'dump': obj.dumps()}
         elif isfunction(obj):
             return {'type': 'SerializedFunction', 'dump': SerializableFunction(obj).dumps()}
Пример #2
0
 def handler(obj):
     try:
         json_handler(obj)
     except Exception:
         if isinstance(obj, SerializableFunction):
             return {'type': 'SerializedFunction', 'dump': obj.dumps()}
         elif isfunction(obj):
             return {'type': 'SerializedFunction', 'dump': SerializableFunction(obj).dumps()}
Пример #3
0
 def default(self, obj):
     from dimagi.utils.web import json_handler
     from couchexport.export import Constant
     if isinstance(obj, Constant):
         return obj.message
     else:
         return json_handler(obj)
Пример #4
0
 def default(self, obj):
     from dimagi.utils.web import json_handler
     from couchexport.export import Constant
     if isinstance(obj, Constant):
         return obj.message
     else:
         return json_handler(obj)
Пример #5
0
    def test_to_complete_json(self):
        json_rep = 'json rep'

        class Klass(object):
            def to_complete_json(self):
                return json_rep

        self.assertEqual(json_rep, json_handler(Klass()))
Пример #6
0
 def test_time_24_hour(self):
     self.assertEqual('23:15:22', json_handler(datetime.time(23, 15, 22)))
Пример #7
0
 def test_time(self):
     self.assertEqual('11:15:22', json_handler(datetime.time(11, 15, 22)))
Пример #8
0
 def custom_json_handler(obj):
     if hasattr(obj, 'stock_on_hand'):
         return obj.stock_on_hand
     return json_handler(obj)
Пример #9
0
 def default(self, obj):
     if isinstance(obj, Constant):
         return obj.message
     else:
         return json_handler(obj)
Пример #10
0
 def custom_json_handler(obj):
     if isinstance(obj, StockTransaction):
         return obj.stock_on_hand
     return json_handler(obj)
Пример #11
0
 def test_time_24_hour(self):
     self.assertEqual('23:15:22', json_handler(datetime.time(23, 15, 22)))
Пример #12
0
 def test_date(self):
     self.assertEqual('2014-01-05', json_handler(datetime.date(2014, 1, 5)))
Пример #13
0
 def test_to_complete_json(self):
     json_rep = 'json rep'
     class Klass(object):
         def to_complete_json(self):
             return json_rep
     self.assertEqual(json_rep, json_handler(Klass()))
Пример #14
0
 def test_datetime(self):
     self.assertEqual(
         '2014-01-05T12:15:05.000000Z',
         json_handler(datetime.datetime(2014, 1, 5, 12, 15, 5)))
Пример #15
0
 def custom_json_handler(obj):
     if hasattr(obj, 'stock_on_hand'):
         return obj.stock_on_hand
     return json_handler(obj)
Пример #16
0
 def test_time(self):
     self.assertEqual('11:15:22', json_handler(datetime.time(11, 15, 22)))
Пример #17
0
 def test_datetime(self):
     self.assertEqual('2014-01-05T12:15:05.000000Z', json_handler(datetime.datetime(2014, 1, 5, 12, 15, 5)))
Пример #18
0
 def test_date(self):
     self.assertEqual('2014-01-05', json_handler(datetime.date(2014, 1, 5)))
Пример #19
0
 def test_decimal(self):
     self.assertEqual(3.14, json_handler(Decimal('3.14')))
Пример #20
0
 def test_decimal(self):
     self.assertEqual(3.14, json_handler(Decimal('3.14')))
Пример #21
0
 def custom_json_handler(obj):
     if isinstance(obj, StockTransaction):
         return obj.stock_on_hand
     return json_handler(obj)