Ticket #15180: urlresolvers-v2.2.diff

File urlresolvers-v2.2.diff, 3.4 KB (added by olaf, 13 years ago)
Line 
1208c208
2< for matches, pat in pattern.reverse_dict.getlist(name):
3---
4> for matches, pat, default_args in pattern.reverse_dict.getlist(name):
5212c212
6< lookups.appendlist(name, (new_matches, p_pattern + pat))
7---
8> lookups.appendlist(name, (new_matches, p_pattern + pat, default_args))
9219c219
10< lookups.appendlist(pattern.callback, (bits, p_pattern))
11---
12> lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
13221c221
14< lookups.appendlist(pattern.name, (bits, p_pattern))
15---
16> lookups.appendlist(pattern.name, (bits, p_pattern, pattern.default_args))
17304c304
18< def reverse(self, lookup_view, *args, **kwargs):
19---
20> def reverse(self, lookup_view, check_default_args=False, *args, **kwargs):
21312c312
22< for possibility, pattern in possibilities:
23---
24> for possibility, pattern, default_args in possibilities:
25319a320,336
26> # first check if some of the requested kwargs are defined as an default arg.
27> # pop them from the requested kwargs so that they won't interfere with the
28> # comparison of the other kwargs. If one of the default_args is requested but
29> # differ with its value the corresponding URL will be ignored.
30> if check_default_args:
31> bak_kwargs = kwargs.copy()
32> continue_upper_loop = False
33> for key in default_args:
34> if key in kwargs:
35> tmp = kwargs.pop(key)
36> if tmp != default_args[key]:
37> continue_upper_loop = True
38> break
39> if continue_upper_loop:
40> # we will restore the original kwargs before continuing.
41> kwargs=bak_kwargs.copy()
42> continue
43323a341,342
44> if check_default_args:
45> kwargs = bak_kwargs.copy()
46343c362
47< def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None):
48---
49> def reverse(viewname, check_default_args=None, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None):
50389,390c408,423
51< return iri_to_uri(u'%s%s' % (prefix, resolver.reverse(view,
52< *args, **kwargs)))
53---
54> try:
55> suffix = resolver.reverse(view, check_default_args=False if not check_default_args else True, *args, **kwargs)
56> except NoReverseMatch as nrm:
57> # check_default_args could be True, False or None.
58> # it is important, that None and False should act a little bit different.
59> # False for example will not allow to use the reverse function to check for the default args.
60> # None on the other hand tries to find a URL without to check for those but if it fails it
61> # will fallback and tries again but including to check them.
62> if check_default_args == False:
63> raise nrm
64> else:
65> if check_default_args != True:
66> suffix = resolver.reverse(view, check_default_args=True, *args, **kwargs)
67> else:
68> raise nrm
69> return iri_to_uri(u'%s%s' % (prefix, suffix))
Back to Top