blob: 9e2c9c7b7620932970e76b37ec8cc74353b9587d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
"""
View which can render and send email from a contact form.
"""
from django import http
from django.urls import reverse_lazy
from django.views.generic.edit import FormView
from .forms import ContactForm, StringKeyedDict
class ContactFormView(FormView):
form_class = ContactForm
recipient_list = None
success_url = reverse_lazy("contact_form_sent")
template_name = "contact/contact_form.html"
def get_context_data(self, **kwargs):
'''
Adds breadcrumb path to every view
'''
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
# special case for pages:
context['breadcrumbs'] = ('contact',)
context['crumb_url'] = None
return context
def form_valid(self, form) -> http.HttpResponse:
form.save()
return super().form_valid(form)
def get_form_kwargs(self) -> StringKeyedDict:
# ContactForm instances require instantiation with an
# HttpRequest.
kwargs = super().get_form_kwargs()
kwargs.update({"request": self.request})
# We may also have been given a recipient list when
# instantiated.
if self.recipient_list is not None:
kwargs.update({"recipient_list": self.recipient_list})
return kwargs
|