Ejemplo n.º 1
0
 def default(self, o):
     if isinstance(o, dt.datetime):
         if o.tzinfo is None or o.tzinfo.utcoffset(o) is None:
             raise NaiveDatetimeException('Tried to encode a naive datetime.')
         return dict(type='encoded_datetime', value=o.isoformat())
     elif isinstance(o, dt.date):
         return dict(type='encoded_date', value=o.isoformat())
     elif isinstance(o, dt.time):
         if o.tzinfo is None or o.tzinfo.utcoffset(o) is None:
             raise NaiveDatetimeException('Tried to encode a naive time.')
         return dict(type='encoded_time', value=o.isoformat())
     elif isinstance(o, Decimal):
         return dict(type='encoded_decimal', value=str(o))
     return super(DateTimeAwareJSONEncoder, self).default(o)
Ejemplo n.º 2
0
 def get_prep_value(self, value):
     value = super(NonNaiveDateTimeField, self).get_prep_value(value)
     if value is not None and (value.tzinfo is None or value.tzinfo.utcoffset(value) is None):
         raise NaiveDatetimeException('Tried to encode a naive datetime.')
     return value