From 2833cf0652983884504a3dcc1c71522b98f1a82f Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Wed, 8 Apr 2020 10:54:48 +0200 Subject: [PATCH] add forms folder, put forms into different files and renamed ReservationForm to BookingForm --- rental/{forms.py => forms/booking.py} | 49 +-------------------------- rental/forms/contact.py | 46 +++++++++++++++++++++++++ rental/views.py | 7 ++-- 3 files changed, 51 insertions(+), 51 deletions(-) rename rental/{forms.py => forms/booking.py} (61%) create mode 100644 rental/forms/contact.py diff --git a/rental/forms.py b/rental/forms/booking.py similarity index 61% rename from rental/forms.py rename to rental/forms/booking.py index 76fbb92..afdc177 100644 --- a/rental/forms.py +++ b/rental/forms/booking.py @@ -1,14 +1,10 @@ from django import forms from rental.models.booking import Booking -from rental.models.contact import Contact -from rental.models.guest import Guest -from rental.models.picture import Picture from rental.models.place import Place -from rental.models.testimonial import Testimonial from rental.enums import PlaceNames -class ReservationForm(forms.Form): +class BookingForm(forms.Form): name = forms.CharField( label="", @@ -76,46 +72,3 @@ class ReservationForm(forms.Form): 'class': 'form-control form-control-lg form-control-a', 'placeholder': '31/12/2020 *'}), required=True) - - -class ContactForm(forms.Form): - - name = forms.CharField( - label='', - widget=forms.TextInput(attrs={ - 'class': 'form-control form-control-lg form-control-a', - 'placeholder': 'Nom *' - }), - required=True, - ) - - email = forms.EmailField( - label='', - widget=forms.EmailInput(attrs={ - 'class': 'form-control form-control-lg form-control-a', - 'placeholder': 'Email *' - }), - required=True, - ) - - subject = forms.CharField( - label='', - widget=forms.TextInput(attrs={ - 'class': 'form-control form-control-lg form-control-a', - 'placeholder': 'Sujet *' - }), - required=True, - ) - - message = forms.CharField( - label='', - # max_length=100, - min_length=4, - widget=forms.Textarea(attrs={ - 'class': 'form-control', - 'cols': '45', - 'rows': '8', - 'placeholder': 'Message *' - }), - required=True - ) diff --git a/rental/forms/contact.py b/rental/forms/contact.py new file mode 100644 index 0000000..f538338 --- /dev/null +++ b/rental/forms/contact.py @@ -0,0 +1,46 @@ +from django import forms +from rental.models.contact import Contact +from rental.models.place import Place + + +class ContactForm(forms.Form): + + name = forms.CharField( + label='', + widget=forms.TextInput(attrs={ + 'class': 'form-control form-control-lg form-control-a', + 'placeholder': 'Nom *' + }), + required=True, + ) + + email = forms.EmailField( + label='', + widget=forms.EmailInput(attrs={ + 'class': 'form-control form-control-lg form-control-a', + 'placeholder': 'Email *' + }), + required=True, + ) + + subject = forms.CharField( + label='', + widget=forms.TextInput(attrs={ + 'class': 'form-control form-control-lg form-control-a', + 'placeholder': 'Sujet *' + }), + required=True, + ) + + message = forms.CharField( + label='', + # max_length=100, + min_length=4, + widget=forms.Textarea(attrs={ + 'class': 'form-control', + 'cols': '45', + 'rows': '8', + 'placeholder': 'Message *' + }), + required=True + ) diff --git a/rental/views.py b/rental/views.py index 42d30d9..5c23235 100644 --- a/rental/views.py +++ b/rental/views.py @@ -3,7 +3,8 @@ from django.db import IntegrityError from django.shortcuts import render, get_object_or_404 from django.views.generic.base import TemplateView from django.utils.translation import gettext_lazy as _ -from rental.forms import ReservationForm, ContactForm +from rental.forms.booking import BookingForm +from rental.forms.contact import ContactForm from rental.models.booking import Booking from rental.models.contact import Contact from rental.models.guest import Guest @@ -54,7 +55,7 @@ def reservation(request): def handle_reservation_form(request, context={}, init_template='rental/reservation.html'): if request.method == 'POST': - form = ReservationForm(request.POST) + form = BookingForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] email = form.cleaned_data['email'] @@ -105,7 +106,7 @@ def handle_reservation_form(request, context={}, init_template='rental/reservati except IntegrityError: form.errors['internal'] = "Une erreur interne est apparue. Merci de recommencer votre requĂȘte." else: - form = ReservationForm() + form = BookingForm() context['form'] = form context['errors'] = form.errors.items()