Ticket #13639: datetime_format.diff

File datetime_format.diff, 2.4 KB (added by ctao, 5 years ago)
  • forms/widgets.py

    diff -r 365044b9174e forms/widgets.py
    a b  
    302302
    303303class DateInput(Input):
    304304    input_type = 'text'
    305     format = '%Y-%m-%d'     # '2006-10-25'
     305    format = formats.get_format('DATE_INPUT_FORMATS')[0] # or '%Y-%m-%d'     # '2006-10-25'
    306306
    307307    def __init__(self, attrs=None, format=None):
    308308        super(DateInput, self).__init__(attrs)
     
    322322        # formatted by HiddenInput using formats.localize_input, which is not
    323323        # necessarily the format used for this widget. Attempt to convert it.
    324324        try:
    325             input_format = formats.get_format('DATE_INPUT_FORMATS')[0]
     325            input_format = self.format
    326326            initial = datetime.date(*time.strptime(initial, input_format)[:3])
    327327        except (TypeError, ValueError):
    328328            pass
     
    330330
    331331class DateTimeInput(Input):
    332332    input_type = 'text'
    333     format = '%Y-%m-%d %H:%M:%S'     # '2006-10-25 14:30:59'
     333    format = formats.get_format('DATETIME_INPUT_FORMATS')[0] #'%Y-%m-%d %H:%M:%S'     # '2006-10-25 14:30:59'
    334334
    335335    def __init__(self, attrs=None, format=None):
    336336        super(DateTimeInput, self).__init__(attrs)
     
    350350        # formatted by HiddenInput using formats.localize_input, which is not
    351351        # necessarily the format used for this widget. Attempt to convert it.
    352352        try:
    353             input_format = formats.get_format('DATETIME_INPUT_FORMATS')[0]
     353            input_format = self.format
    354354            initial = datetime.datetime(*time.strptime(initial, input_format)[:6])
    355355        except (TypeError, ValueError):
    356356            pass
     
    358358
    359359class TimeInput(Input):
    360360    input_type = 'text'
    361     format = '%H:%M:%S'     # '14:30:59'
     361    format = formats.get_format('TIME_INPUT_FORMATS')[0] #'%H:%M:%S'     # '14:30:59'
    362362
    363363    def __init__(self, attrs=None, format=None):
    364364        super(TimeInput, self).__init__(attrs)
     
    377377        # formatted by HiddenInput using formats.localize_input, which is not
    378378        # necessarily the format used for this  widget. Attempt to convert it.
    379379        try:
    380             input_format = formats.get_format('TIME_INPUT_FORMATS')[0]
     380            input_format = self.format
    381381            initial = datetime.time(*time.strptime(initial, input_format)[3:6])
    382382        except (TypeError, ValueError):
    383383            pass
Back to Top