Ticket #2784: http-methods-patch.diff
File http-methods-patch.diff, 4.3 KB (added by , 18 years ago) |
---|
-
Users/smn/Documents/Repositories/Django/django/conf/urls/defaults.py
7 7 8 8 include = lambda urlconf_module: [urlconf_module] 9 9 10 request_methods = ['GET','POST','PUT','DELETE'] 11 10 12 def patterns(prefix, *tuples): 11 13 pattern_list = [] 12 14 for t in tuples: … … 14 16 default_kwargs = t[2:] 15 17 if type(view_or_include) == list: 16 18 pattern_list.append(RegexURLResolver(regex, view_or_include[0], *default_kwargs)) 19 elif type(view_or_include) == dict: 20 for m in [method for method in view_or_include.keys() if method in request_methods]: 21 pattern_list.append(RegexURLPattern(regex, prefix and (prefix + '.' + view_or_include.get(m)) or view_or_include.get(m), method=m, *default_kwargs)) 17 22 else: 18 23 pattern_list.append(RegexURLPattern(regex, prefix and (prefix + '.' + view_or_include) or view_or_include, *default_kwargs)) 19 24 return pattern_list -
Users/smn/Documents/Repositories/Django/django/core/urlresolvers.py
84 84 return str(value) # TODO: Unicode? 85 85 86 86 class RegexURLPattern(object): 87 def __init__(self, regex, callback, default_args=None):87 def __init__(self, regex, callback, method=None, default_args=None): 88 88 # regex is a string representing a regular expression. 89 89 # callback is either a string like 'foo.views.news.stories.story_detail' 90 90 # which represents the path to a module and a view function name, or a 91 91 # callable object (view). 92 92 self.regex = re.compile(regex) 93 self.method = method 93 94 if callable(callback): 94 95 self._callback = callback 95 96 else: … … 97 98 self._callback_str = callback 98 99 self.default_args = default_args or {} 99 100 100 def resolve(self, path ):101 def resolve(self, path, method=None): 101 102 match = self.regex.search(path) 102 if match :103 if match and method == self.method: 103 104 # If there are any named groups, use those as kwargs, ignoring 104 105 # non-named groups. Otherwise, pass all non-named arguments as 105 106 # positional arguments. … … 148 149 self.callback = None 149 150 self.default_kwargs = default_kwargs or {} 150 151 151 def resolve(self, path ):152 def resolve(self, path, method=None): 152 153 tried = [] 153 154 match = self.regex.search(path) 154 155 if match: 155 156 new_path = path[match.end():] 156 157 for pattern in self.urlconf_module.urlpatterns: 157 158 try: 158 sub_match = pattern.resolve(new_path )159 sub_match = pattern.resolve(new_path,method=method) 159 160 except Resolver404, e: 160 161 tried.extend([(pattern.regex.pattern + ' ' + t) for t in e.args[0]['tried']]) 161 162 else: … … 220 221 result = reverse_helper(self.regex, *args, **kwargs) 221 222 return result + sub_match 222 223 223 def resolve(path, urlconf=None ):224 def resolve(path, urlconf=None, method=None): 224 225 if urlconf is None: 225 226 from django.conf import settings 226 227 urlconf = settings.ROOT_URLCONF -
Users/smn/Documents/Repositories/Django/django/core/handlers/base.py
62 62 63 63 resolver = urlresolvers.RegexURLResolver(r'^/', settings.ROOT_URLCONF) 64 64 try: 65 callback, callback_args, callback_kwargs = resolver.resolve(path )65 callback, callback_args, callback_kwargs = resolver.resolve(path, method=request.method) 66 66 67 67 # Apply view middleware 68 68 for middleware_method in self._view_middleware: