2015-02-01 18:55:24 +01:00
|
|
|
"""
|
|
|
|
This module defines the views of the contact_form app.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
from __future__ import absolute_import
|
2015-02-01 18:55:24 +01:00
|
|
|
|
|
|
|
from django.shortcuts import redirect
|
2018-11-19 23:28:40 +01:00
|
|
|
from django.urls import reverse_lazy
|
2023-02-18 22:46:48 +01:00
|
|
|
from django.views.generic import FormView, TemplateView
|
2015-02-01 18:55:24 +01:00
|
|
|
|
|
|
|
from .forms import ContactForm
|
|
|
|
|
|
|
|
|
|
|
|
class ContactFormView(FormView):
|
|
|
|
"""
|
|
|
|
This is the contact form view.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
|
2015-02-01 18:55:24 +01:00
|
|
|
form_class = ContactForm
|
2023-02-18 22:46:48 +01:00
|
|
|
template_name = "contact_form/contact_form.html"
|
|
|
|
success_url = reverse_lazy("contact_success")
|
2015-02-01 18:55:24 +01:00
|
|
|
|
|
|
|
def get_form_kwargs(self, **kwargs):
|
|
|
|
kwargs = super(ContactFormView, self).get_form_kwargs(**kwargs)
|
2023-02-18 22:46:48 +01:00
|
|
|
kwargs["request"] = self.request
|
2015-02-01 18:55:24 +01:00
|
|
|
return kwargs
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
initial = super(ContactFormView, self).get_initial()
|
|
|
|
currentuser = self.request.user
|
2018-11-19 23:28:40 +01:00
|
|
|
if currentuser.is_authenticated:
|
2023-02-18 22:46:48 +01:00
|
|
|
initial["name"] = currentuser.get_full_name() or currentuser.username
|
|
|
|
initial["email"] = currentuser.email
|
2015-02-01 18:55:24 +01:00
|
|
|
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.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
|
|
|
|
template_name = "contact_form/contact_success.html"
|