Ticket #12072: patch-12072-e.diff
File patch-12072-e.diff, 4.0 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/templates/tests.py
1031 1031 'url08': (u'{% url метка_оператора v %}', {'v': 'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 1032 1032 'url09': (u'{% url метка_оператора_2 tag=v %}', {'v': 'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 1033 1033 'url10': ('{% url regressiontests.templates.views.client_action id=client.id,action="two words" %}', {'client': {'id': 1}}, '/url_tag/client/1/two%20words/'), 1034 'url11': ('{% url regressiontests.templates.views.client_action id=client.id,action="==" %}', {'client': {'id': 1}}, '/url_tag/client/1/==/'), 1035 'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action="," %}', {'client': {'id': 1}}, '/url_tag/client/1/,/'), 1036 'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action=arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'), 1034 1037 1035 1038 # Failures 1036 1039 'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError), 1037 1040 'url-fail02': ('{% url no_such_view %}', {}, urlresolvers.NoReverseMatch), 1038 1041 'url-fail03': ('{% url regressiontests.templates.views.client %}', {}, urlresolvers.NoReverseMatch), 1042 'url-fail04': ('{% url view id, %}', {}, template.TemplateSyntaxError), 1043 'url-fail05': ('{% url view id= %}', {}, template.TemplateSyntaxError), 1044 'url-fail06': ('{% url view a.id=id %}', {}, template.TemplateSyntaxError), 1045 'url-fail07': ('{% url view a.id!id %}', {}, template.TemplateSyntaxError), 1046 'url-fail08': ('{% url view id="unterminatedstring %}', {}, template.TemplateSyntaxError), 1047 'url-fail09': ('{% url view id=", %}', {}, template.TemplateSyntaxError), 1039 1048 1040 1049 # {% url ... as var %} 1041 1050 'url-asvar01': ('{% url regressiontests.templates.views.index as url %}', {}, ''), -
django/template/defaulttags.py
1071 1071 return TemplateTagNode(tag) 1072 1072 templatetag = register.tag(templatetag) 1073 1073 1074 # Regex for URL arguments including filters 1075 url_arg_re = re.compile( 1076 r"(?:(%(name)s)=)?(%(value)s(?:\|%(name)s(?::%(value)s)?)*)" % { 1077 'name':'\w+', 1078 'value':'''(?:(?:'[^']*')|(?:"[^"]*")|(?:[\w\.-]+))'''}, 1079 re.VERBOSE) 1080 1074 1081 def url(parser, token): 1075 1082 """ 1076 1083 Returns an absolute URL matching given view with its parameters. … … 1118 1125 asvar = bits.next() 1119 1126 break 1120 1127 else: 1121 for arg in bit.split(","): 1122 if '=' in arg: 1123 k, v = arg.split('=', 1) 1124 k = k.strip() 1125 kwargs[k] = parser.compile_filter(v) 1126 elif arg: 1127 args.append(parser.compile_filter(arg)) 1128 end = 0 1129 for i, match in enumerate(url_arg_re.finditer(bit)): 1130 if (i == 0 and match.start() != 0) or \ 1131 (i > 0 and (bit[end:match.start()] != ',')): 1132 raise TemplateSyntaxError("Malformed arguments to url tag") 1133 end = match.end() 1134 name, value = match.group(1), match.group(2) 1135 if name: 1136 kwargs[name] = parser.compile_filter(value) 1137 else: 1138 args.append(parser.compile_filter(value)) 1139 if end != len(bit): 1140 raise TemplateSyntaxError("Malformed arguments to url tag") 1141 1128 1142 return URLNode(viewname, args, kwargs, asvar) 1129 1143 url = register.tag(url) 1130 1144