Ejemplo n.º 1
0
 def select_report_instance_days(self, report_id, tags):
     with cursor() as cur:
         cur.execute("""SELECT day FROM report_instance_day
                            WHERE report_id=? AND tags=?""",
                           [report_id, tags])
         dates = [row['day'] for row in cur.fetchall()]
         return [util.datetime_from_date(d) for d in dates]
Ejemplo n.º 2
0
def encoder_default(obj):
    if hasattr(obj, 'for_json'):
        res = obj.for_json()
        if isinstance(res, dict) and '__type__' not in res:
            _init_lib_classes()
            res['__type__'] = obj._json_type
        return res
    if isinstance(obj, datetime.date):
        if not isinstance(obj, datetime.datetime):
            obj = datetime_from_date(obj)
        return {'__type__': 'date', 'arg': datetime_to_timestamp(obj) * 1000}
    if isinstance(obj, uuid.UUID):
        return {'__type__': 'UUID', 'arg': obj.hex}
    raise TypeError('Not JSON-serializable: type %s object %r' %
                    (type(obj), obj))
Ejemplo n.º 3
0
    def test_custom_types(self):
        d = {
            'id': uuid.uuid1(),
            'id2': uuid.uuid4(),
            'dt': datetime.datetime.utcnow(),
            'da': datetime.datetime.utcnow(),
            'ss': SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
        }
        self.assertEqual(d, serialize.json_loads(serialize.mjson(d)))

        dt = datetime.datetime.utcnow()
        self.assertEqual(util.datetime_from_date(dt.date()),
                         serialize.json_loads(serialize.mjson(dt.date())))

        ext_d = json.loads(
            serialize.json_dumps_external(util.dictwithout(d, 'ss')))
        self.assertEqual(d['id2'].hex, ext_d['id2'])
Ejemplo n.º 4
0
 def _day_before(self, minus_days):
     return util.datetime_from_date(
         (datetime.datetime.utcnow() -
          datetime.timedelta(days=minus_days)).date())