Created
January 27, 2013 05:42
-
-
Save ojii/4646656 to your computer and use it in GitHub Desktop.
Class based view decorators for Django
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
def cbv_decorator(decorator): | |
""" | |
Turns a normal view decorator into a class-based-view decorator. | |
Usage: | |
@cbv_decorator(login_required) | |
class MyClassBasedView(View): | |
pass | |
""" | |
def _decorator(cls): | |
cls.dispatch = method_decorator(decorator)(cls.dispatch) | |
return cls | |
return _decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment