Ticket #3530: permalink_with_additional_function_arg_fixed.diff
File permalink_with_additional_function_arg_fixed.diff, 1.3 KB (added by , 18 years ago) |
---|
-
django/db/models/__init__.py
18 18 19 19 # Decorator. Takes a function that returns a tuple in this format: 20 20 # (viewname, viewargs, viewkwargs) 21 # Optionally takes a function which should either return an object with 22 # an attribute 'urlconf' or directly a python list which is used instead of 23 # settings.ROOT_URLCONF 21 24 # Returns a function that calls urlresolvers.reverse() on that data, to return 22 25 # the URL for those parameters. 23 def permalink(func ):26 def permalink(func, get_urlconf_func = None): 24 27 from django.core.urlresolvers import reverse 25 28 def inner(*args, **kwargs): 29 # Find urlconf ... 30 urlconf = None 31 if get_urlconf_func != None: 32 urlconf = get_urlconf_func() 33 if type(urlconf) != list: 34 # If type is no list, we assume it is a request object and 35 # look for a 'urlconf' attribute 36 urlconf = getattr(urlconf, 'urlconf', None) 37 26 38 bits = func(*args, **kwargs) 27 39 viewname = bits[0] 28 return reverse(bits[0], None, *bits[1:3])40 return reverse(bits[0], urlconf, *bits[1:3]) 29 41 return inner 30 42 31 43 class LazyDate(object):