Exemple #1
0
 def default(self, o):
     if isinstance(o, datetime.datetime):
         d = datetime_safe.new_datetime(o)
         return d.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
     elif isinstance(o, datetime.date):
         d = datetime_safe.new_date(o)
         return d.strftime(self.DATE_FORMAT)
     elif isinstance(o, datetime.time):
         return o.strftime(self.TIME_FORMAT)
     elif isinstance(o, decimal.Decimal):
         return str(o)
     else:
         return super(DjangoJSONEncoder, self).default(o)
Exemple #2
0
 def default(self, o):
     if isinstance(o, datetime.datetime):
         d = datetime_safe.new_datetime(o)
         return d.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
     elif isinstance(o, datetime.date):
         d = datetime_safe.new_date(o)
         return d.strftime(self.DATE_FORMAT)
     elif isinstance(o, datetime.time):
         return o.strftime(self.TIME_FORMAT)
     elif isinstance(o, decimal.Decimal):
         return str(o)
     else:
         return super(DjangoJSONEncoder, self).default(o)
def localize_input(value, default=None):
    """
    Checks if an input value is a localizable type and returns it
    formatted with the appropriate formatting string of the current locale.
    """
    if isinstance(value, (decimal.Decimal, float, int, long)):
        return number_format(value)
    if isinstance(value, datetime.datetime):
        value = datetime_safe.new_datetime(value)
        format = smart_str(default or get_format('DATETIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.date):
        value = datetime_safe.new_date(value)
        format = smart_str(default or get_format('DATE_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.time):
        format = smart_str(default or get_format('TIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    return value
Exemple #4
0
def localize_input(value, default=None):
    """
    Checks if an input value is a localizable type and returns it
    formatted with the appropriate formatting string of the current locale.
    """
    if isinstance(value, (decimal.Decimal, float, int, long)):
        return number_format(value)
    if isinstance(value, datetime.datetime):
        value = datetime_safe.new_datetime(value)
        format = smart_str(default or get_format("DATETIME_INPUT_FORMATS")[0])
        return value.strftime(format)
    elif isinstance(value, datetime.date):
        value = datetime_safe.new_date(value)
        format = smart_str(default or get_format("DATE_INPUT_FORMATS")[0])
        return value.strftime(format)
    elif isinstance(value, datetime.time):
        format = smart_str(default or get_format("TIME_INPUT_FORMATS")[0])
        return value.strftime(format)
    return value