Ticket #27724: ticket_27724.diff

File ticket_27724.diff, 2.7 KB (added by Adonys Alea Boffill, 8 years ago)
  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index 801067e..46e3e20 100644
    a b class SelectDateWidget(Widget):  
    912912    template_name = 'django/forms/widgets/select_date.html'
    913913    input_type = 'select'
    914914    select_widget = Select
    915     date_re = re.compile(r'(\d{4})-(\d\d?)-(\d\d?)$')
     915    date_re = re.compile(r'(\d{4}|0)-(\d\d?)-(\d\d?)$')
    916916
    917917    def __init__(self, attrs=None, years=None, months=None, empty_label=None):
    918918        self.attrs = attrs or {}
  • tests/forms_tests/widget_tests/test_selectdatewidget.py

    diff --git a/tests/forms_tests/widget_tests/test_selectdatewidget.py b/tests/forms_tests/widget_tests/test_selectdatewidget.py
    index 2429420..119a02a 100644
    a b class SelectDateWidgetTest(WidgetTest):  
    485485        self.assertIs(self.widget.value_omitted_from_data({'field_day': '1'}, {}, 'field'), False)
    486486        data = {'field_day': '1', 'field_month': '12', 'field_year': '2000'}
    487487        self.assertIs(self.widget.value_omitted_from_data(data, {}, 'field'), False)
     488
     489    def test_regexp_date_re(self):
     490        # valid formats
     491        self.assertIsNotNone(self.widget.date_re.match('2000-1-1'))  # 1 digit for (day & month)
     492        self.assertIsNotNone(self.widget.date_re.match('2000-10-15'))  # 2 digit for (day & month)
     493        self.assertIsNotNone(self.widget.date_re.match('2000-01-01'))  # 2 digit for (day & month) starting on 0
     494        self.assertIsNotNone(self.widget.date_re.match('2000-01-0'))  # day not provided
     495        self.assertIsNotNone(self.widget.date_re.match('2000-0-01'))  # month not provided
     496        self.assertIsNotNone(self.widget.date_re.match('0-01-01'))  # year not provided
     497        self.assertIsNotNone(self.widget.date_re.match('2000-0-0'))  # day & month not provided
     498        self.assertIsNotNone(self.widget.date_re.match('0-01-0'))  # day & year not provided
     499        self.assertIsNotNone(self.widget.date_re.match('0-0-01'))  # month & year not provided
     500        self.assertIsNotNone(self.widget.date_re.match('0-0-0'))  # day, month & year not provided
     501        # invalid formats
     502        self.assertIsNone(self.widget.date_re.match('2000-01-001'))  # invalid day
     503        self.assertIsNone(self.widget.date_re.match('2000-001-01'))  # invalid month
     504        # invalid year formats (year accept only 4 digits or 0)
     505        self.assertIsNone(self.widget.date_re.match('2-01-01'))
     506        self.assertIsNone(self.widget.date_re.match('20-01-01'))
     507        self.assertIsNone(self.widget.date_re.match('200-01-01'))
     508        self.assertIsNone(self.widget.date_re.match('20000-01-01'))
Back to Top