Very nice snippets, though they're meant to work only with Django's default class views.<p>A few months ago I started using a small class-based views library called aino-utkik[1] and haven't looked back.<p>Instead of this:<p><pre><code> class ArtistLogin(FormView):
form_class = ArtistLoginForm
template_name = 'artists/artist_login.html'
def get(self, request, *args, **kwargs):
request.session.set_test_cookie()
return super(ArtistLogin, self).get(request, *args, **kwargs)
def form_valid(self, form):
login(self.request, form.artist)
return HttpResponseRedirect(reverse('artist_mypage'))
def get_form_kwargs(self):
kwargs = super(ArtistLogin, self).get_form_kwargs()
kwargs['request'] = self.request
return kwargs
</code></pre>
I can write this:<p><pre><code> class ArtistLogin(View):
def setup(self):
self.c.form = ArtistLoginForm(
request=self.request, data=self.request.POST or None)
def get(self):
self.request.session.set_test_cookie()
def post(self):
if self.c.form.is_valid():
login(self.request, self.c.form.artist)
return HttpResponseRedirect(reverse('artist_mypage'))
</code></pre>
which I find way more elegant.<p>[1] <a href="https://github.com/aino/aino-utkik" rel="nofollow">https://github.com/aino/aino-utkik</a>