Ticket #2370: urlresolve.patch

File urlresolve.patch, 2.2 KB (added by anonymous, 18 years ago)
  • django/conf/urls/defaults.py

     
    1010def patterns(prefix, *tuples):
    1111    pattern_list = []
    1212    for t in tuples:
    13         if type(t[1]) == list:
    14             pattern_list.append(RegexURLResolver(t[0], t[1][0]))
     13        reg_ex, view_or_include = t[:2]
     14        default_args            = t[2:]
     15        if isinstance (view_or_include, list):
     16            pattern_list.append(RegexURLResolver(reg_ex, view_or_include[0], * default_args))
    1517        else:
    16             pattern_list.append(RegexURLPattern(t[0], prefix and (prefix + '.' + t[1]) or t[1], *t[2:]))
     18            pattern_list.append(RegexURLPattern(reg_ex, prefix and (prefix + '.' + view_or_include) or view_or_include, *default_args))
    1719    return pattern_list
  • django/core/urlresolvers.py

     
    130130        return reverse_helper(self.regex, *args, **kwargs)
    131131
    132132class RegexURLResolver(object):
    133     def __init__(self, regex, urlconf_name):
     133    def __init__(self, regex, urlconf_name, default_args=None):
    134134        # regex is a string representing a regular expression.
    135135        # urlconf_name is a string representing the module containing urlconfs.
    136136        self.regex = re.compile(regex)
    137137        self.urlconf_name = urlconf_name
    138138        self.callback = None
     139        self.default_args = default_args or {}
    139140
    140141    def resolve(self, path):
    141142        tried = []
     
    149150                    tried.extend([(pattern.regex.pattern + '   ' + t) for t in e.args[0]['tried']])
    150151                else:
    151152                    if sub_match:
    152                         return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2])
     153                        sub_match_dict = dict (self.default_args, **sub_match[2])
     154                        return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match_dict)
    153155                    tried.append(pattern.regex.pattern)
    154156            raise Resolver404, {'tried': tried, 'path': new_path}
    155157
Back to Top