Skip to content

Instantly share code, notes, and snippets.

@konradhalas
Last active December 16, 2015 09:48
Show Gist options
  • Save konradhalas/5415296 to your computer and use it in GitHub Desktop.
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.
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