Ticket #6449: django-datetime-filter.2.patch

File django-datetime-filter.2.patch, 1.5 KB (added by Harm Geerts, 17 years ago)

Alternativate patch that introduces a new datetime filter which in implements 'x' and 'X' to access DATE_FORMAT and TIME_FORMAT

  • django/template/defaultfilters.py

     
    614614# DATES           #
    615615###################
    616616
    617 def date(value, arg=None):
    618     """Formats a date according to the given format."""
     617def datetime(value, arg=None):
     618    """Formats a datetime according to the given format."""
    619619    from django.utils.dateformat import format
    620620    if not value:
    621621        return u''
    622622    if arg is None:
     623        arg = settings.DATETIME_FORMAT
     624    elif arg == 'x':
    623625        arg = settings.DATE_FORMAT
     626    elif arg == 'X':
     627        arg = settings.TIME_FORMAT
    624628    return format(value, arg)
     629datetime.is_safe = False
     630
     631def date(value, arg=None):
     632    """Formats a date according to the given format."""
     633    if arg is None:
     634        arg = settings.DATE_FORMAT
     635    return datetime(value, arg)
    625636date.is_safe = False
    626637
    627638def time(value, arg=None):
    628639    """Formats a time according to the given format."""
    629     from django.utils.dateformat import time_format
    630     if value in (None, u''):
    631         return u''
    632640    if arg is None:
    633641        arg = settings.TIME_FORMAT
    634     return time_format(value, arg)
     642    return datetime(value, arg)
    635643time.is_safe = False
    636644
    637645def timesince(value, arg=None):
     
    797805register.filter(center)
    798806register.filter(cut)
    799807register.filter(date)
     808register.filter(datetime)
    800809register.filter(default)
    801810register.filter(default_if_none)
    802811register.filter(dictsort)
Back to Top