Created
March 1, 2012 18:17
-
-
Save mjtamlyn/1951841 to your computer and use it in GitHub Desktop.
Alternative dispatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Current dispatch method | |
| def dispatch(self, request, *args, **kwargs): | |
| # Try to dispatch to the right method; if a method doesn't exist, | |
| # defer to the error handler. Also defer to the error handler if the | |
| # request method isn't on the approved list. | |
| if request.method.lower() in self.http_method_names: | |
| handler = getattr(self, request.method.lower(), self.http_method_not_allowed) | |
| else: | |
| handler = self.http_method_not_allowed | |
| self.request = request | |
| self.args = args | |
| self.kwargs = kwargs | |
| return handler(request, *args, **kwargs) | |
| # New dispatch method | |
| def dispatch(self, request, *args, **kwargs): | |
| # Try to dispatch to the right method; if a method doesn't exist, | |
| # defer to the error handler. Also defer to the error handler if the | |
| # request method isn't on the approved list. | |
| if request.method.lower() in self.http_method_names: | |
| handler = getattr(self, request.method.lower(), self.http_method_not_allowed) | |
| else: | |
| handler = self.http_method_not_allowed | |
| self.request = request | |
| self.args = args | |
| self.kwargs = kwargs | |
| request = self.process_request(request) | |
| return handler(request, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment