Ticket #9366: datefilters.diff

File datefilters.diff, 1.6 KB (added by Bob Thomas, 16 years ago)

Use translated strings for date/time formats, add a datetime filter

  • django/template/defaultfilters.py

     
    99
    1010from django.template import Variable, Library
    1111from django.conf import settings
    12 from django.utils.translation import ugettext, ungettext
     12from django.utils.translation import ugettext, ungettext, get_date_formats
    1313from django.utils.encoding import force_unicode, iri_to_uri
    1414from django.utils.safestring import mark_safe, SafeData
    1515
     
    627627    if not value:
    628628        return u''
    629629    if arg is None:
    630         arg = settings.DATE_FORMAT
     630        arg = get_date_formats()[0]
    631631    return format(value, arg)
    632632date.is_safe = False
    633633
     634def datetime(value, arg=None):
     635    """Formats a date and time according to the given format."""
     636    from django.utils.dateformat import format
     637    if not value:
     638        return u''
     639    if arg is None:
     640        arg = get_date_formats()[1]
     641    return format(value, arg)
     642datetime.is_safe = False
     643
    634644def time(value, arg=None):
    635645    """Formats a time according to the given format."""
    636646    from django.utils.dateformat import time_format
    637647    if value in (None, u''):
    638648        return u''
    639649    if arg is None:
    640         arg = settings.TIME_FORMAT
     650        arg = get_date_formats()[2]
    641651    return time_format(value, arg)
    642652time.is_safe = False
    643653
     
    808818register.filter(center)
    809819register.filter(cut)
    810820register.filter(date)
     821register.filter(datetime)
    811822register.filter(default)
    812823register.filter(default_if_none)
    813824register.filter(dictsort)
Back to Top