mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-12 13:26:47 +00:00
refactor: improve readability (#8)
This commit is contained in:
parent
780188e7d6
commit
c55ff54032
1 changed files with 22 additions and 17 deletions
|
|
@ -5,24 +5,29 @@ from rental.models.contact import Contact
|
||||||
|
|
||||||
|
|
||||||
def view(request):
|
def view(request):
|
||||||
"""Handle contactForm."""
|
"""
|
||||||
|
Handle contact form submission after validation and redirect to success page.
|
||||||
|
"""
|
||||||
|
|
||||||
if request.method == 'POST':
|
# create blank form or populates fields using post request data
|
||||||
form = ContactForm(request.POST)
|
form = ContactForm(
|
||||||
if form.is_valid():
|
request.POST) if request.method == 'POST' else ContactForm()
|
||||||
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()
|
# simply display contact page, persist form values in case of errors
|
||||||
contact.send_notification()
|
if request.method == 'GET' or not form.is_valid():
|
||||||
|
return render(request, 'rental/contact.html', {'form': form})
|
||||||
|
|
||||||
return render(request, 'rental/contact_merci.html', {})
|
# create contact object to db
|
||||||
|
contact = Contact.objects.create(
|
||||||
|
name=form.cleaned_data['name'],
|
||||||
|
email=form.cleaned_data['email'],
|
||||||
|
subject=form.cleaned_data['subject'],
|
||||||
|
message=form.cleaned_data['message']
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
# handle messaging
|
||||||
form = ContactForm()
|
contact.send_confirmation()
|
||||||
context = {'form': form}
|
contact.send_notification()
|
||||||
return render(request, 'rental/contact.html', context)
|
|
||||||
|
# redirect to success page
|
||||||
|
return render(request, 'rental/contact_merci.html', {})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue