Ticket #15092: 15092-2.patch

File 15092-2.patch, 2.6 KB (added by claudep, 3 years ago)

Adding 2 more tests

  • django/template/defaulttags.py

    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index 701515a..fa54f45 100644
    a b def now(parser, token): 
    10491049
    10501050        It is {% now "jS F Y H:i" %}
    10511051    """
    1052     bits = token.contents.split('"')
    1053     if len(bits) != 3:
     1052    bits = token.split_contents()
     1053    if len(bits) != 2:
    10541054        raise TemplateSyntaxError("'now' statement takes one argument")
    1055     format_string = bits[1]
     1055    format_string = bits[1][1:-1]
    10561056    return NowNode(format_string)
    10571057
    10581058@register.tag
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index 1a1b360..92a6cb1 100644
    a b class Templates(unittest.TestCase): 
    14621462
    14631463            ### NOW TAG ########################################################
    14641464            # Simple case
    1465             'now01': ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),
    1466 
    1467             # Check parsing of escaped and special characters
    1468             'now02': ('{% now "j "n" Y"%}', {}, template.TemplateSyntaxError),
    1469         #    'now03': ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + '"' + str(datetime.now().month) + '"' + str(datetime.now().year)),
    1470         #    'now04': ('{% now "j \nn\n Y"%}', {}, str(datetime.now().day) + '\n' + str(datetime.now().month) + '\n' + str(datetime.now().year))
     1465            'now01': ('{% now "j n Y" %}', {}, "%d %d %d" % (
     1466                datetime.now().day, datetime.now().month, datetime.now().year)),
    14711467            # Check parsing of locale strings
    1472             'now05': ('{% now "DATE_FORMAT" %}', {},  date_format(datetime.now())),
     1468            'now02': ('{% now "DATE_FORMAT" %}', {},  date_format(datetime.now())),
     1469            # Also accept simple quotes - #15092
     1470            'now03': ("{% now 'j n Y' %}", {}, "%d %d %d" % (
     1471                datetime.now().day, datetime.now().month, datetime.now().year)),
     1472            'now04': ("{% now 'DATE_FORMAT' %}", {},  date_format(datetime.now())),
     1473            'now05': ('''{% now 'j "n" Y'%}''', {}, '''%d "%d" %d''' % (
     1474                datetime.now().day, datetime.now().month, datetime.now().year)),
     1475            'now06': ('''{% now "j 'n' Y"%}''', {}, '''%d '%d' %d''' % (
     1476                datetime.now().day, datetime.now().month, datetime.now().year)),
    14731477
    14741478            ### URL TAG ########################################################
    14751479            # Successes
Back to Top