﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16626	login_required attribute in class-based Generic Views	szczav	nobody	"Current generic views implementation allows for using login_required decorator in two ways:
1. By using decorator in urls: 
{{{
#!python
    login_required(MyView.as_view())
}}}
2. By overriding dispatch method:
{{{
#!python
   @method_decorator(login_required)
   def dispatch(self, request, *args, **kwargs):
       return super(self.__class__, self).dispatch(request, *args, **kwargs)
}}}

First way doesn't allow for subclassing decorated view and is ugly because separates part of class logic into separate file. Second way is also ugly - it makes you override dispatch() method in every place where you want to use one, simple decorator. It's especially annoying on websites which have a lot of content visible only for signed users. It's unpleasant to read and violates DRY. The best solution to this problem is creating login_required class attribute for all generic views. It'd work for all generic views this way:
{{{
#!python
    class MyView(TemplateView):
        login_required = True
        template_name = 'some_template.html'
}}}
Patch attached."	New feature	closed	Generic views	dev	Normal	worksforme	login_required decorator view generic views	szczav@…	Unreviewed	1	0	0	0	0	0
