Ticket #3672: date-time-widgets-tests-7601.diff

File date-time-widgets-tests-7601.diff, 2.2 KB (added by Adi J. Sieker, 16 years ago)

update the patch again, removed the usage for DATE_FORMAT from the translation.

  • django/newforms/widgets.py

     
    88    from sets import Set as set   # Python 2.3 fallback
    99
    1010import copy
     11import datetime
    1112from itertools import chain
    1213
     14from django.conf import settings
     15from django.utils import dateformat
    1316from django.utils.datastructures import MultiValueDict
    1417from django.utils.html import escape, conditional_escape
    1518from django.utils.translation import ugettext
     
    1821from util import flatatt
    1922
    2023__all__ = (
    21     'Widget', 'TextInput', 'PasswordInput',
     24    'Widget', 'TextInput', 'DateTextInput', 'TimeTextInput', 'PasswordInput',
    2225    'HiddenInput', 'MultipleHiddenInput',
    2326    'FileInput', 'DateTimeInput', 'Textarea', 'CheckboxInput',
    2427    'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect',
     
    9598class TextInput(Input):
    9699    input_type = 'text'
    97100
     101class DateTextInput(TextInput):
     102    """Renders value in text input using default or specified date format."""
     103    def __init__(self, format=None, attrs=None):
     104        super(DateTextInput, self).__init__(attrs)
     105        self.format = format or settings.DATE_FORMAT
     106
     107    def render(self, name, value, attrs=None):
     108        if value and (isinstance(value, datetime.date) or isinstance(value, datetime.datetime)):
     109            formatted_value = dateformat.format(value, self.format)
     110        else:
     111            formatted_value = None
     112        return super(DateTextInput, self).render(name, formatted_value, attrs)
     113
     114class TimeTextInput(TextInput):
     115    """Renders time in text input using default or specified time format."""
     116    def __init__(self, format=None, attrs=None):
     117        super(TimeTextInput, self).__init__(attrs)
     118        self.format = format or settings.TIMEFORMAT
     119
     120    def render(self, name, value, attrs=None):
     121        if value and (isinstance(value, datetime.time) or isinstance(value, datetime.datetime)):
     122            formatted_value = dateformat.time_format(value, self.format)
     123        else:
     124            formatted_value = None
     125        return super(TimeTextInput, self).render(name, formatted_value, attrs)
     126
    98127class PasswordInput(Input):
    99128    input_type = 'password'
    100129
Back to Top