Last active
December 16, 2015 09:48
-
-
Save konradhalas/5415296 to your computer and use it in GitHub Desktop.
Simple view wrapper. Now you can convert old, ugly view function into class based view.
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.views.generic import View | |
from django.core.exceptions import ImproperlyConfigured | |
from django.contrib.auth.views import login | |
class WrapperView(View): | |
@property | |
def view_function(self): | |
raise ImproperlyConfigured("You must define a 'view_function'.") | |
def dispatch(self, *args, **kwargs): | |
kwargs.update(self.get_settings()) | |
return self.view_function.im_func(*args, **kwargs) | |
def get_settings(self): | |
return {} | |
class LoginView(WrapperView): | |
view_function = login | |
template_name = 'accounts/login.html' | |
def get_settings(self): | |
return { | |
'template_name': self.template_name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment