Ticket #15092: fix_now.patch

File fix_now.patch, 3.0 KB (added by Stephen Kelly, 14 years ago)

Fixes bug

  • django/template/defaulttags.py

    commit bb8200391b10cae732e54945ff3b5807ae55a595
    Author: Stephen Kelly <steveire@gmail.com>
    Date:   Sat Jan 15 23:21:03 2011 +0100
    
        Make the now tag accept single quoted strings.
        
        Also move the test for a invalid string argument to a more suitable
        place.
    
    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index 0662b5f..693a9d7 100644
    a b def now(parser, token):  
    10711071
    10721072        It is {% now "jS F Y H:i" %}
    10731073    """
    1074     bits = token.contents.split('"')
    1075     if len(bits) != 3:
     1074    bits = token.split_contents()
     1075    if len(bits) != 2:
    10761076        raise TemplateSyntaxError("'now' statement takes one argument")
    1077     format_string = bits[1]
     1077    format_string = bits[1][1:-1]
    10781078    return NowNode(format_string)
    10791079now = register.tag(now)
    10801080
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index 99776e6..74bead1 100644
    a b class Templates(unittest.TestCase):  
    934934            'ifequal-split08': (r"{% ifequal a 'I\'m happy' %}yes{% else %}no{% endifequal %}", {'a': "I'm happy"}, "yes"),
    935935            'ifequal-split09': (r"{% ifequal a 'slash\man' %}yes{% else %}no{% endifequal %}", {'a': r"slash\man"}, "yes"),
    936936            'ifequal-split10': (r"{% ifequal a 'slash\man' %}yes{% else %}no{% endifequal %}", {'a': r"slashman"}, "no"),
     937            # Even though smart_split accepts 'j 'n' Y' as one item, FilterExpression does not.
     938            'ifequal-split11': (r"{% ifequal a 'j 'n' Y' %}yes{% else %}no{% endifequal %}", {'a': r"j 'n' Y"}, template.TemplateSyntaxError),
    937939
    938940            # NUMERIC RESOLUTION
    939941            'ifequal-numeric01': ('{% ifequal x 5 %}yes{% endifequal %}', {'x': '5'}, ''),
    class Templates(unittest.TestCase):  
    13491351            'now01': ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),
    13501352
    13511353            # Check parsing of escaped and special characters
    1352             'now02': ('{% now "j "n" Y"%}', {}, template.TemplateSyntaxError),
    1353         #    'now03': ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + '"' + str(datetime.now().month) + '"' + str(datetime.now().year)),
    1354         #    'now04': ('{% now "j \nn\n Y"%}', {}, str(datetime.now().day) + '\n' + str(datetime.now().month) + '\n' + str(datetime.now().year))
     1354            'now02': ('{% now "j " n " Y"%}', {}, template.TemplateSyntaxError),
     1355            'now03': ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + ' "' + str(datetime.now().month) + '" ' + str(datetime.now().year)),
     1356            'now04': ('{% now "j \nn\n Y"%}', {}, '{% now "j \nn\n Y"%}'),
     1357
     1358            'now05': ("{% now 'j n Y' %}", {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),
    13551359
    13561360            ### URL TAG ########################################################
    13571361            # Successes
Back to Top