Ticket #2370: urlresolve.patch
File urlresolve.patch, 2.2 KB (added by , 18 years ago) |
---|
-
django/conf/urls/defaults.py
10 10 def patterns(prefix, *tuples): 11 11 pattern_list = [] 12 12 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)) 15 17 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)) 17 19 return pattern_list -
django/core/urlresolvers.py
130 130 return reverse_helper(self.regex, *args, **kwargs) 131 131 132 132 class RegexURLResolver(object): 133 def __init__(self, regex, urlconf_name ):133 def __init__(self, regex, urlconf_name, default_args=None): 134 134 # regex is a string representing a regular expression. 135 135 # urlconf_name is a string representing the module containing urlconfs. 136 136 self.regex = re.compile(regex) 137 137 self.urlconf_name = urlconf_name 138 138 self.callback = None 139 self.default_args = default_args or {} 139 140 140 141 def resolve(self, path): 141 142 tried = [] … … 149 150 tried.extend([(pattern.regex.pattern + ' ' + t) for t in e.args[0]['tried']]) 150 151 else: 151 152 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) 153 155 tried.append(pattern.regex.pattern) 154 156 raise Resolver404, {'tried': tried, 'path': new_path} 155 157