Ticket #15263: 15263_now_tag.diff

File 15263_now_tag.diff, 2.7 KB (added by dmclain, 9 years ago)

Sackcloth and ashes tour: Updated docs to fix patch errors and reflect new feature.

  • django/template/defaulttags.py

    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index ea49c19..e65bfdc 100644
    a b class NowNode(Node): 
    381381
    382382    def render(self, context):
    383383        from datetime import datetime
    384         from django.utils.dateformat import DateFormat
    385         df = DateFormat(datetime.now())
    386         return df.format(self.format_string)
     384        from django.utils import formats
     385        from django.utils import dateformat
     386        now = datetime.now()
     387        try:
     388            return formats.date_format(now, self.format_string)
     389        except AttributeError:
     390            try:
     391                return dateformat.format(now, self.format_string)
     392            except AttributeError:
     393                return ''
    387394
    388395class SpacelessNode(Node):
    389396    def __init__(self, nodelist):
  • docs/ref/templates/builtins.txt

    diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
    index 1767b5b..c607015 100644
    a b escaped, because it's not a format character:: 
    727727
    728728This would display as "It is the 4th of September".
    729729
     730The format passed can also be one of the predefined ones ``DATE_FORMAT``,
     731``DATETIME_FORMAT``, ``SHORT_DATE_FORMAT`` or ``SHORT_DATETIME_FORMAT``. Note
     732that predefined formats may vary depending on the current locale.
     733
    730734.. templatetag:: regroup
    731735
    732736regroup
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index 75f3b4f..abfdb8d 100644
    a b from django.template.loaders import app_directories, filesystem, cached 
    2121from django.test.utils import get_warnings_state, restore_warnings_state,\
    2222    setup_test_template_loader, restore_template_loaders
    2323from django.utils import unittest
     24from django.utils.formats import date_format
    2425from django.utils.translation import activate, deactivate, ugettext as _
    2526from django.utils.safestring import mark_safe
    2627from django.utils.tzinfo import LocalTimezone
    class Templates(unittest.TestCase): 
    14221423            'now02': ('{% now "j "n" Y"%}', {}, template.TemplateSyntaxError),
    14231424        #    'now03': ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + '"' + str(datetime.now().month) + '"' + str(datetime.now().year)),
    14241425        #    'now04': ('{% now "j \nn\n Y"%}', {}, str(datetime.now().day) + '\n' + str(datetime.now().month) + '\n' + str(datetime.now().year))
     1426            # Check parsing of locale strings
     1427            'now05': ('{% now "DATE_FORMAT" %}', {},  date_format(datetime.now())),
    14251428
    14261429            ### URL TAG ########################################################
    14271430            # Successes
Back to Top