コード例 #1
0
ファイル: util.py プロジェクト: dimagi/commcare-hq
 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
ファイル: writers.py プロジェクト: kkrampa/couchexport
 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
ファイル: export.py プロジェクト: wbnigeria/couchexport
 def default(self, obj):
     if isinstance(obj, Constant):
         return obj.message
     else:
         return json_handler(obj)
コード例 #10
0
ファイル: views.py プロジェクト: aristide/commcare-hq
 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)