~canonical-django/canonical-django/project-template

« back to all changes in this revision

Viewing changes to trunk/python-packages/django/contrib/localflavor/generic/forms.py

  • Committer: Matthew Nuzum
  • Date: 2008-11-13 05:46:03 UTC
  • Revision ID: matthew.nuzum@canonical.com-20081113054603-v0kvr6z6xyexvqt3
adding to version control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)