PageRenderTime 18ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://code.google.com/p/mango-py/
Python | 48 lines | 32 code | 5 blank | 11 comment | 3 complexity | 9a8444da476191ee02e86c94ece3c524 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django import forms
  2. DEFAULT_DATE_INPUT_FORMATS = (
  3. '%Y-%m-%d', '%d/%m/%Y', '%d/%m/%y', # '2006-10-25', '25/10/2006', '25/10/06'
  4. '%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006'
  5. '%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006'
  6. '%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006'
  7. '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006'
  8. )
  9. DEFAULT_DATETIME_INPUT_FORMATS = (
  10. '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
  11. '%Y-%m-%d %H:%M', # '2006-10-25 14:30'
  12. '%Y-%m-%d', # '2006-10-25'
  13. '%d/%m/%Y %H:%M:%S', # '25/10/2006 14:30:59'
  14. '%d/%m/%Y %H:%M', # '25/10/2006 14:30'
  15. '%d/%m/%Y', # '25/10/2006'
  16. '%d/%m/%y %H:%M:%S', # '25/10/06 14:30:59'
  17. '%d/%m/%y %H:%M', # '25/10/06 14:30'
  18. '%d/%m/%y', # '25/10/06'
  19. )
  20. class DateField(forms.DateField):
  21. """
  22. A date input field which uses non-US date input formats by default.
  23. """
  24. def __init__(self, input_formats=None, *args, **kwargs):
  25. input_formats = input_formats or DEFAULT_DATE_INPUT_FORMATS
  26. super(DateField, self).__init__(input_formats=input_formats, *args, **kwargs)
  27. class DateTimeField(forms.DateTimeField):
  28. """
  29. A date and time input field which uses non-US date and time input formats
  30. by default.
  31. """
  32. def __init__(self, input_formats=None, *args, **kwargs):
  33. input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS
  34. super(DateTimeField, self).__init__(input_formats=input_formats, *args, **kwargs)
  35. class SplitDateTimeField(forms.SplitDateTimeField):
  36. """
  37. Split date and time input fields which use non-US date and time input
  38. formats by default.
  39. """
  40. def __init__(self, input_date_formats=None, input_time_formats=None, *args, **kwargs):
  41. input_date_formats = input_date_formats or DEFAULT_DATE_INPUT_FORMATS
  42. super(SplitDateTimeField, self).__init__(input_date_formats=input_date_formats,
  43. input_time_formats=input_time_formats, *args, **kwargs)