예제 #1
0
 def _format_value(self, value):
     if self.is_localized and not self.manual_format:
         return formats.localize_input(value)
     elif hasattr(value, 'strftime'):
         value = datetime_safe.new_date(value)
         return value.strftime(self.format)
     return value
예제 #2
0
 def urls(self, plugin_name, easy_instance_field):
     if isinstance(easy_instance_field.field, models.DateField):
         d = easy_instance_field.raw_value
         return ['%s%s/%s/%s/%s/%s/' % (
             easy_instance_field.model.url(),
             plugin_name, easy_instance_field.field.name,
             str(d.year),
             datetime_safe.new_date(d).strftime('%b').lower(),
             d.day)]
예제 #3
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) + six.integer_types):
        return number_format(value)
    elif isinstance(value, datetime.datetime):
        value = datetime_safe.new_datetime(value)
        format = force_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 = force_str(default or get_format('DATE_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.time):
        format = force_str(default or get_format('TIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    return value