Created
December 3, 2010 18:52
-
-
Save sjzabel/727362 to your computer and use it in GitHub Desktop.
Adding a Mixin to all Django class based Generic 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
from django.contrib.auth.decorators import login_required | |
from django.utils.decorators import method_decorator | |
from django.views import generic | |
from new import classobj | |
import re | |
class LoginRequiredMixin(object): | |
@method_decorator(login_required) | |
def dispatch(self,request, *args, **kwargs ): | |
return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs) | |
for class_name in [key for key in generic.__dict__.keys() if re.match('.+View$',key)]: | |
locals()[class_name] = classobj(class_name,(LoginRequiredMixin,generic.__dict__[class_name]),{}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment