예제 #1
0
 def __init__(self, attrs=None, format=None):
     super(TimeInput, self).__init__(attrs)
     if format:
         self.format = format
         self.manual_format = True
     else:
         self.format = formats.get_format('TIME_INPUT_FORMATS')[0]
         self.manual_format = False
예제 #2
0
 def _has_changed(self, initial, data):
     # If our field has show_hidden_initial=True, initial will be a string
     # formatted by HiddenInput using formats.localize_input, which is not
     # necessarily the format used for this  widget. Attempt to convert it.
     try:
         input_format = formats.get_format('TIME_INPUT_FORMATS')[0]
         initial = datetime.datetime.strptime(initial, input_format).time()
     except (TypeError, ValueError):
         pass
     return super(TimeInput, self)._has_changed(self._format_value(initial), data)
예제 #3
0
def get_formats():
    """
    Returns all formats strings required for i18n to work
    """
    FORMAT_SETTINGS = (
        'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
        'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
        'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
        'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
        'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
    )
    result = {}
    for module in [settings] + get_format_modules(reverse=True):
        for attr in FORMAT_SETTINGS:
            result[attr] = get_format(attr)
    src = []
    for k, v in result.items():
        if isinstance(v, (six.string_types, int)):
            src.append("formats['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(smart_text(v))))
        elif isinstance(v, (tuple, list)):
            v = [javascript_quote(smart_text(value)) for value in v]
            src.append("formats['%s'] = ['%s'];\n" % (javascript_quote(k), "', '".join(v)))
    return ''.join(src)