villafleurie/rental/views/contact.py
Ruidy 780188e7d6
Refactor (#7)
* crete setting module to split prod and dev configs

* fix calendar midmatch

* lint imports using isort

* doc: add doctrings
2020-07-31 08:02:10 +02:00

28 lines
821 B
Python

from django.shortcuts import render
from rental.forms.contact import ContactForm
from rental.models.contact import Contact
def view(request):
"""Handle contactForm."""
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
contact = Contact.objects.create(
name=form.cleaned_data['name'],
email=form.cleaned_data['email'],
subject=form.cleaned_data['subject'],
message=form.cleaned_data['message']
)
contact.send_confirmation()
contact.send_notification()
return render(request, 'rental/contact_merci.html', {})
else:
form = ContactForm()
context = {'form': form}
return render(request, 'rental/contact.html', context)