Ticket #13275: 13275.diff

File 13275.diff, 7.1 KB (added by Chris Beaven, 15 years ago)
  • tests/regressiontests/templates/urls.py

    ### Eclipse Workspace Patch 1.0
    #P Django
     
    66
    77    # Test urls for testing reverse lookups
    88    (r'^$', views.index),
    9     (r'^client/(\d+)/$', views.client),
     9    (r'^client/([\d,]+)/$', views.client),
    1010    (r'^client/(?P<id>\d+)/(?P<action>[^/]+)/$', views.client_action),
     11    (r'^client/(?P<client_id>\d+)/(?P<action>[^/]+)/$', views.client_action),
    1112    url(r'^named-client/(\d+)/$', views.client2, name="named.client"),
    1213
    1314    # Unicode strings are permitted everywhere.
  • tests/regressiontests/templates/tests.py

     
    364364                settings.TEMPLATE_STRING_IF_INVALID = invalid_str
    365365                for is_cached in (False, True):
    366366                    try:
     367                        start = datetime.now()
    367368                        test_template = loader.get_template(name)
     369                        end = datetime.now()
    368370                        output = self.render(test_template, vals)
     371                        if end-start > timedelta(seconds=0.1):
     372                            failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s'): %s -- FAILED. Took too long to parse test" % (is_cached, invalid_str, name))
    369373                    except ContextStackException:
    370374                        failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s'): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, name))
    371375                        continue
     
    11751179            # Successes
    11761180            'legacyurl02': ('{% url regressiontests.templates.views.client_action id=client.id,action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
    11771181            'legacyurl02a': ('{% url regressiontests.templates.views.client_action client.id,"update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
     1182            'legacyurl02b': ("{% url regressiontests.templates.views.client_action id=client.id,action='update' %}", {'client': {'id': 1}}, '/url_tag/client/1/update/'),
     1183            'legacyurl02c': ("{% url regressiontests.templates.views.client_action client.id,'update' %}", {'client': {'id': 1}}, '/url_tag/client/1/update/'),
    11781184            'legacyurl10': ('{% url regressiontests.templates.views.client_action id=client.id,action="two words" %}', {'client': {'id': 1}}, '/url_tag/client/1/two%20words/'),
    11791185            'legacyurl13': ('{% url regressiontests.templates.views.client_action id=client.id, action=arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'),
    11801186            'legacyurl14': ('{% url regressiontests.templates.views.client_action client.id, arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'),
     1187            'legacyurl16': ('{% url regressiontests.templates.views.client_action action="update",id="1" %}', {}, '/url_tag/client/1/update/'),
     1188            'legacyurl16a': ("{% url regressiontests.templates.views.client_action action='update',id='1' %}", {}, '/url_tag/client/1/update/'),
     1189            'legacyurl17': ('{% url regressiontests.templates.views.client_action client_id=client.my_id,action=action %}', {'client': {'my_id': 1}, 'action': 'update'}, '/url_tag/client/1/update/'),
    11811190
    11821191            'url01': ('{% url regressiontests.templates.views.client client.id %}', {'client': {'id': 1}}, '/url_tag/client/1/'),
    11831192            'url02': ('{% url regressiontests.templates.views.client_action id=client.id action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
    11841193            'url02a': ('{% url regressiontests.templates.views.client_action client.id "update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
     1194            'url02b': ("{% url regressiontests.templates.views.client_action id=client.id action='update' %}", {'client': {'id': 1}}, '/url_tag/client/1/update/'),
     1195            'url02c': ("{% url regressiontests.templates.views.client_action client.id 'update' %}", {'client': {'id': 1}}, '/url_tag/client/1/update/'),
    11851196            'url03': ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'),
    11861197            'url04': ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
    11871198            'url05': (u'{% url метка_оператора v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'),
     
    11951206            'url13': ('{% url regressiontests.templates.views.client_action id=client.id action=arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'),
    11961207            'url14': ('{% url regressiontests.templates.views.client_action client.id arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'),
    11971208            'url15': ('{% url regressiontests.templates.views.client_action 12 "test" %}', {}, '/url_tag/client/12/test/'),
     1209            'url18': ('{% url regressiontests.templates.views.client "1,2" %}', {}, '/url_tag/client/1,2/'),
    11981210
    11991211            # Failures
    12001212            'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError),
  • django/template/defaulttags.py

     
    10651065    return TemplateTagNode(tag)
    10661066templatetag = register.tag(templatetag)
    10671067
    1068 # Backwards compatibility check which will fail against for old comma
    1069 # separated arguments in the url tag.
    1070 url_backwards_re = re.compile(r'''(('[^']*'|"[^"]*"|[^,]+)=?)+$''')
    1071 
    10721068def url(parser, token):
    10731069    """
    10741070    Returns an absolute URL matching given view with its parameters.
     
    11171113        asvar = bits[-1]
    11181114        bits = bits[:-2]
    11191115
    1120     # Backwards compatibility: {% url urlname arg1,arg2 %} or
    1121     # {% url urlname arg1,arg2 as foo %} cases.
    1122     if bits:
    1123         old_args = ''.join(bits)
    1124         if not url_backwards_re.match(old_args):
    1125             bits = old_args.split(",")
     1116    # Backwards compatibility: check for the old comma separated format
     1117    # {% url urlname arg1,arg2 %}
     1118    if bits and ',' in bits[0]:
     1119        check_old_format = True
     1120        for bit in bits[1:-1]:
     1121            if ',' not in bit:
     1122                check_old_format = False
     1123                break
     1124    else:
     1125        check_old_format = False
     1126    if check_old_format:
     1127        match = kwarg_re.match(bits[0])
     1128        if match:
     1129            value = match.groups()[1]
     1130            # Check for the old format by trying to parse the first argument. An
     1131            # exception will be raised if the comma is unexpected (i.e. outside
     1132            # of a static string).
     1133            try:
     1134                parser.compile_filter(value)
     1135            except TemplateSyntaxError:
     1136                bits = ''.join(bits).split(',')
    11261137
    11271138    if len(bits):
    11281139        for bit in bits:
Back to Top