diff --git a/django/newforms/extras/widgets.py b/django/newforms/extras/widgets.py index af6b14b08d..e3ef1d7f69 100644 --- a/django/newforms/extras/widgets.py +++ b/django/newforms/extras/widgets.py @@ -3,6 +3,7 @@ Extra HTML Widget classes """ import datetime +import re from django.newforms.widgets import Widget, Select from django.utils.dates import MONTHS @@ -10,6 +11,8 @@ from django.utils.safestring import mark_safe __all__ = ('SelectDateWidget',) +RE_DATE = re.compile(r'(\d{4})-(\d\d?)-(\d\d?)$') + class SelectDateWidget(Widget): """ A Widget that splits date input into three +Accepts a datetime or a string: + +>>> w.render('mydate', datetime.date(2010, 4, 15)) == w.render('mydate', '2010-04-15') +True + +Invalid dates still render the failed date: +>>> print w.render('mydate', '2010-02-31') + + + + Using a SelectDateWidget in a form: >>> class GetDate(Form):