From 19915c83a94460c9f851f67af265e8c242185182 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Wed, 8 Apr 2020 11:18:18 +0200 Subject: [PATCH] add views folder, put template and error views to their own files; update urls.py and html templates accordingly --- rental/templates/rental/base.html | 22 +++++++++++++--------- rental/templates/rental/index.html | 4 ++-- rental/urls.py | 23 +++++++++++++---------- rental/views/errors.py | 9 +++++++++ rental/views/home.py | 17 +++++++++++++++++ rental/{ => views}/views.py | 24 ------------------------ villafleurie/urls.py | 13 +++---------- 7 files changed, 57 insertions(+), 55 deletions(-) create mode 100644 rental/views/errors.py create mode 100644 rental/views/home.py rename rental/{ => views}/views.py (90%) diff --git a/rental/templates/rental/base.html b/rental/templates/rental/base.html index 781818f..8b59e2c 100644 --- a/rental/templates/rental/base.html +++ b/rental/templates/rental/base.html @@ -186,17 +186,19 @@ > - + Réserver @@ -250,14 +252,16 @@ @@ -280,13 +284,13 @@ Hébergements
  • - Réservation + Réservation
  • - À propos + À propos
  • - Contact + Contact
  • diff --git a/rental/templates/rental/index.html b/rental/templates/rental/index.html index 0f43454..5e13282 100644 --- a/rental/templates/rental/index.html +++ b/rental/templates/rental/index.html @@ -95,7 +95,7 @@

    @@ -117,7 +117,7 @@

    diff --git a/rental/urls.py b/rental/urls.py index d3f521e..d858605 100644 --- a/rental/urls.py +++ b/rental/urls.py @@ -1,21 +1,24 @@ -from django.urls import path -from . import views -from villafleurie import settings -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 django.contrib.staticfiles.urls import static, staticfiles_urlpatterns +from django.urls import path +from villafleurie import settings +from rental.views import home, views + app_name = 'rental' urlpatterns = [ + path('a-propos/', home.About.as_view(), name='about'), + path('legal/', home.Legal.as_view(), name='legal'), + path('partenaires/', home.Partners.as_view(), name='partners'), + path('services/', home.Services.as_view(), name='services'), + + path('contact/', views.contact, name='contact'), + path('reservation/', views.reservation, name='reservation'), + path('', views.index, name='index'), path('hebergements/', views.liste_location, name='list_place'), path('/', views.location, name='detail_place'), - path('calendar//', views.calendar, name='calendar') + # path('calendar//', views.calendar, name='calendar'), ] urlpatterns += staticfiles_urlpatterns() diff --git a/rental/views/errors.py b/rental/views/errors.py new file mode 100644 index 0000000..23c248c --- /dev/null +++ b/rental/views/errors.py @@ -0,0 +1,9 @@ +from django.shortcuts import render + + +def handler404(request, exception): + return render(request, 'rental/404.html', status=404) + + +def handler500(request): + return render(request, 'rental/500.html', status=500) diff --git a/rental/views/home.py b/rental/views/home.py new file mode 100644 index 0000000..e08db6c --- /dev/null +++ b/rental/views/home.py @@ -0,0 +1,17 @@ +from django.views.generic.base import TemplateView + + +class Legal(TemplateView): + template_name = 'rental/legal.html' + + +class About(TemplateView): + template_name = 'rental/about.html' + + +class Partners(TemplateView): + template_name = 'rental/partners.html' + + +class Services(TemplateView): + template_name = 'rental/service.html' diff --git a/rental/views.py b/rental/views/views.py similarity index 90% rename from rental/views.py rename to rental/views/views.py index 5c23235..b4c40cb 100644 --- a/rental/views.py +++ b/rental/views/views.py @@ -1,7 +1,6 @@ from django.core.exceptions import ValidationError 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.booking import BookingForm from rental.forms.contact import ContactForm @@ -152,26 +151,3 @@ def contact(request): context = {'form': form} return render(request, 'rental/contact.html', context) - -class Legal(TemplateView): - template_name = 'rental/legal.html' - - -class About(TemplateView): - template_name = 'rental/about.html' - - -class Partners(TemplateView): - template_name = 'rental/partners.html' - - -class Services(TemplateView): - template_name = 'rental/service.html' - - -def handler404(request, exception): - return render(request, 'rental/404.html', status=404) - - -def handler500(request): - return render(request, 'rental/500.html', status=500) diff --git a/villafleurie/urls.py b/villafleurie/urls.py index 08e36d3..87057c4 100644 --- a/villafleurie/urls.py +++ b/villafleurie/urls.py @@ -2,19 +2,12 @@ from django.contrib import admin from django.urls import path from django.conf import settings from django.conf.urls import include, url -from rental import views urlpatterns = [ path('admin/', admin.site.urls), - path('contact/', views.contact, name='contact'), - path('a-propos/', views.About.as_view(), name='about'), - path('reservation/', views.reservation, name='reservation'), - path('legal/', views.Legal.as_view(), name='legal'), - path('partenaires/', views.Partners.as_view(), name='partners'), - path('services/', views.Services.as_view(), name='services'), - path('', include('rental.urls', namespace='rental')), + path('', include('rental.urls', namespace='rental')) ] -handler404 = 'rental.views.handler404' -handler500 = 'rental.views.handler500' +handler500 = 'rental.views.errors.handler500' +handler404 = 'rental.views.errors.handler404'