Created
March 2, 2012 09:33
-
-
Save meshy/1957251 to your computer and use it in GitHub Desktop.
Suggested new dispatch flow for class based views.
This file contains 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
# @meshy's suggestion: | |
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.prepare_view(request, handler, *args, **kwargs) | |
return handler(request, *args, **kwargs) | |
# Could probably do with a better name... | |
def prepare_view(self, request, handler, *args, **kwargs): | |
"""Set local variables before the dispatch handler is called.""" | |
self.request = request | |
self.args = args | |
self.kwargs = kwargs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment