Ticket #11559: urlresolvers.reverse.hack.patch

File urlresolvers.reverse.hack.patch, 1.5 KB (added by cwb, 15 years ago)

Hack to get parameterised parent namespace urlconfs to reverse (against 1.1)

Line 
1338a339,367
2>
3> # CWB: This is a hack to get namespaced URLs to reverse when the base
4> # has named parameters (may work for positional, but not tested at all).
5> pattern = prefix
6> possibility = normalize(pattern) # The magical regex reverse function!
7> # Below copied from _populate above and slightly altered
8> for result, params in possibility:
9> copy_args = [v for v in args]
10> copy_kwargs = kwargs.copy()
11> if args:
12> if len(args) < len(params):
13> continue
14> # Pop arguments to ensure the right number are passed on to the
15> # resolver.
16> unicode_args = [force_unicode(copy_args.pop(0)) for v in params]
17> candidate = result % dict(zip(params, unicode_args))
18> else:
19> if not set(params).issubset(set(kwargs.keys())):
20> continue
21> # Pop arguments to ensure the right number are passed on to the
22> # resolver.
23> unicode_kwargs = dict([(k, force_unicode(copy_kwargs.pop(k))) for k in params])
24> candidate = result % unicode_kwargs
25> if re.search(u'^%s' % pattern, candidate, re.UNICODE):
26> prefix = candidate
27> else:
28> raise NoReverseMatch(
29> "Reverse for '%s' with arguments '%s' and keyword arguments\
30> '%s' not found." % (pattern, args, kwargs))
31341c370
32< *args, **kwargs)))
33---
34> *copy_args, **copy_kwargs)))
Back to Top