Django

Code

root/django/trunk/django/contrib/localflavor/generic/forms.py

Revision 7971, 1.6 kB (checked in by jacob, 2 months ago)

Fixed #7741: django.newforms is now django.forms. This is obviously a backwards-incompatible change. There's a warning upon import of django.newforms itself, but deeper imports will raise errors.

  • Property svn:eol-style set to native
Line 
1 from django import forms
2
3 DEFAULT_DATE_INPUT_FORMATS = (
4     '%Y-%m-%d', '%d/%m/%Y', '%d/%m/%y', # '2006-10-25', '25/10/2006', '25/10/06'
5     '%b %d %Y', '%b %d, %Y',            # 'Oct 25 2006', 'Oct 25, 2006'
6     '%d %b %Y', '%d %b, %Y',            # '25 Oct 2006', '25 Oct, 2006'
7     '%B %d %Y', '%B %d, %Y',            # 'October 25 2006', 'October 25, 2006'
8     '%d %B %Y', '%d %B, %Y',            # '25 October 2006', '25 October, 2006'
9 )
10
11 DEFAULT_DATETIME_INPUT_FORMATS = (
12     '%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
13     '%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
14     '%Y-%m-%d',              # '2006-10-25'
15     '%d/%m/%Y %H:%M:%S',     # '25/10/2006 14:30:59'
16     '%d/%m/%Y %H:%M',        # '25/10/2006 14:30'
17     '%d/%m/%Y',              # '25/10/2006'
18     '%d/%m/%y %H:%M:%S',     # '25/10/06 14:30:59'
19     '%d/%m/%y %H:%M',        # '25/10/06 14:30'
20     '%d/%m/%y',              # '25/10/06'
21 )
22
23 class DateField(forms.DateField):
24     """
25     A date input field which uses non-US date input formats by default.
26     """
27     def __init__(self, input_formats=None, *args, **kwargs):
28         input_formats = input_formats or DEFAULT_DATE_INPUT_FORMATS
29         super(DateField, self).__init__(input_formats=input_formats, *args, **kwargs)
30
31 class DateTimeField(forms.DateTimeField):
32     """
33     A date and time input field which uses non-US date and time input formats
34     by default.
35     """
36     def __init__(self, input_formats=None, *args, **kwargs):
37         input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS
38         super(DateTimeField, self).__init__(input_formats=input_formats, *args, **kwargs)
Note: See TracBrowser for help on using the browser.