1 | 208c208
|
---|
2 | < for matches, pat in pattern.reverse_dict.getlist(name):
|
---|
3 | ---
|
---|
4 | > for matches, pat, default_args in pattern.reverse_dict.getlist(name):
|
---|
5 | 212c212
|
---|
6 | < lookups.appendlist(name, (new_matches, p_pattern + pat))
|
---|
7 | ---
|
---|
8 | > lookups.appendlist(name, (new_matches, p_pattern + pat, default_args))
|
---|
9 | 219c219
|
---|
10 | < lookups.appendlist(pattern.callback, (bits, p_pattern))
|
---|
11 | ---
|
---|
12 | > lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
|
---|
13 | 221c221
|
---|
14 | < lookups.appendlist(pattern.name, (bits, p_pattern))
|
---|
15 | ---
|
---|
16 | > lookups.appendlist(pattern.name, (bits, p_pattern, pattern.default_args))
|
---|
17 | 304c304
|
---|
18 | < def reverse(self, lookup_view, *args, **kwargs):
|
---|
19 | ---
|
---|
20 | > def reverse(self, lookup_view, check_default_args=False, *args, **kwargs):
|
---|
21 | 312c312
|
---|
22 | < for possibility, pattern in possibilities:
|
---|
23 | ---
|
---|
24 | > for possibility, pattern, default_args in possibilities:
|
---|
25 | 319a320,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
|
---|
43 | 323a341,342
|
---|
44 | > if check_default_args:
|
---|
45 | > kwargs = bak_kwargs.copy()
|
---|
46 | 343c362
|
---|
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):
|
---|
50 | 389,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))
|
---|