duck-booking-tool/accounts/views.py

41 lines
983 B
Python
Raw Normal View History

2015-10-20 14:26:25 +00:00
# -*- coding: utf-8
"""
Views for the accounts module
"""
2015-01-12 15:51:54 +00:00
from django.shortcuts import render
from django.views import generic
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.forms import UserCreationForm
class RegistrationFormView(generic.View):
2015-10-20 14:26:25 +00:00
"""
Class to display the registration form
"""
2015-01-12 15:51:54 +00:00
form_class = UserCreationForm
template_name = 'accounts/registration.html'
def get(self, request):
2015-10-20 14:26:25 +00:00
"""
Implementation of the GET method
"""
2015-01-12 15:51:54 +00:00
form = self.form_class()
2015-10-20 14:26:25 +00:00
return render(request, self.template_name, {'form': form})
2015-01-12 15:51:54 +00:00
def post(self, request):
2015-10-20 14:26:25 +00:00
"""
Implementation of the POST method
"""
2015-01-12 15:51:54 +00:00
form = self.form_class(request.POST)
if form.is_valid():
form.save()
2014-12-17 12:30:58 +00:00
return HttpResponseRedirect(reverse('booking:list'))
2015-01-12 15:51:54 +00:00
return render(request, self.template_name, {'form': form})