gva/gnuviechadmin/contact_form/views.py
Jan Dittberner 385838580b implement contact form
- implement contact_form.forms.ContactForm
- implement contact_form.views.ContactFormView and
  contact_form.views.ContactSuccessView
- add new URL patterns 'contact_form' and 'contact_success' in
  contact_form.urls
- add contact_form templates base.html, contact_form.html, contact_form.txt,
  contact_form_subject.txt and contact_success.html
- add german translation for new strings
- add contact_form to .coveragerc
- add generated code documentation for contact_form app
- add changelog entry
2015-02-01 19:33:53 +01:00

50 lines
1.3 KiB
Python

"""
This module defines the views of the contact_form app.
"""
from __future__ import absolute_import, unicode_literals
from django.shortcuts import redirect
from django.core.urlresolvers import reverse_lazy
from django.views.generic import (
FormView,
TemplateView,
)
from .forms import ContactForm
class ContactFormView(FormView):
"""
This is the contact form view.
"""
form_class = ContactForm
template_name = 'contact_form/contact_form.html'
success_url = reverse_lazy('contact_success')
def get_form_kwargs(self, **kwargs):
kwargs = super(ContactFormView, self).get_form_kwargs(**kwargs)
kwargs['request'] = self.request
return kwargs
def get_initial(self):
initial = super(ContactFormView, self).get_initial()
currentuser = self.request.user
if currentuser.is_authenticated():
initial['name'] = (
currentuser.get_full_name() or currentuser.username)
initial['email'] = currentuser.email
return initial
def form_valid(self, form):
form.save(False)
return redirect(self.get_success_url())
class ContactSuccessView(TemplateView):
"""
This view is shown after successful contact form sending.
"""
template_name = 'contact_form/contact_success.html'