From c9ce373a4d30973c6b3d7c65124053d8bd5e793e Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Fri, 3 Jan 2020 16:12:07 +0100 Subject: [PATCH] calendar api request --- README.md | 8 +++----- docker-compose.yml | 1 - rental/bookings.py | 14 +++++++------- rental/forms.py | 4 ++-- rental/tasks.py | 6 ++---- rental/views.py | 5 ++--- villafleurie/settings.py | 2 ++ 7 files changed, 18 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a53e441..2cae195 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Villafleurie : moteur de réservation autonome -`V 0.1 Le site est structuré. Il reste à appliquer le contenu et les visuels` +`V 1.0 Le site est prêt à l'emploi` Auteur : Ruidy Nemausat @@ -46,7 +46,7 @@ Le visiteur doit pouvoir : 1. Page d'accueil - Landing page -- CTA = "Réserver maintenant" +- CTA = "Réserver" 2. Page logement @@ -99,8 +99,6 @@ Le visiteur doit pouvoir : ## TO DO -- Gestion du calendrier -- Tester la synchro avec Google calendar - Ajouter un date picker dans le formulaire de réservation, changer les placeholders (j'ai pas envie de jouer avec JQuery) - Envoyer devis réservation par mail et notification aux hôtes (put it in a background process, personnaliser les htmails : contact, admin et réservation) - Ajout page/module de paiement @@ -119,7 +117,7 @@ Le visiteur doit pouvoir : - Système de facturation: CRUD Réservations et envoi. Automatisation si possible - Réservation page : Ajouter des photos. Renvoyer vers la page Location onClick sur Réserver TX. Proposer Upsells : navette + location voiture. - Vider le contenu du folder root ? -- Page confirmation message contact envoyé +- Pages confirmation message contact envoyé, reservations réussies ou non (expliquer pourquoi) - SSL certificate ## BUGS diff --git a/docker-compose.yml b/docker-compose.yml index e60cc64..f751801 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,6 @@ services: web: &web build: . - # command: bash -c "python manage.py migrate && python manage.py loaddata villafleurie.json && gunicorn -w 4 villafleurie.wsgi -b 0.0.0.0:8000" command: bash -c "python manage.py migrate && gunicorn -w 4 villafleurie.wsgi -b 0.0.0.0:8000" volumes: - .:/villafleurie diff --git a/rental/bookings.py b/rental/bookings.py index 232a437..9d10609 100644 --- a/rental/bookings.py +++ b/rental/bookings.py @@ -16,7 +16,10 @@ def build_calendar_api_service(): creds = None # If modifying these scopes, delete the file token.pickle. - SCOPES = ['https://www.googleapis.com/auth/calendar'] + SCOPES = [ + 'https://www.googleapis.com/auth/calendar', + 'https://www.googleapis.com/auth/calendar.events' + ] # The file token.pickle stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. @@ -42,7 +45,6 @@ def build_calendar_api_service(): 'T2': "burik7aclvhc7vsboh06c179uo@group.calendar.google.com", 'T3': "fu7h30p0gk4a2p4nvo7nsbgpok@group.calendar.google.com" } - return service, calendars @@ -117,7 +119,6 @@ def get_bookings(place): synchronize_calendars(place) booked_dates = Reservation.objects.filter(place=place) - # if booking.place.name == f"{place.name}"] return [booking for booking in booked_dates] @@ -134,7 +135,6 @@ def check_availability(place, start_date, end_date): def update_calendar(reservation): """ push new reservation to master calendar """ # authenticate and build service - # event.insert(calendarId, summary="Guest", description="Message", end, start ) service, calendars = build_calendar_api_service() start = reservation.start.strftime('%Y-%m-%d') end = reservation.end.strftime('%Y-%m-%d') @@ -151,8 +151,8 @@ def update_calendar(reservation): "date": end }, } - ) + ).execute() -if __name__ == "__main__": - update_calendar(reservation) +# if __name__ == "__main__": +# update_calendar(reservation) diff --git a/rental/forms.py b/rental/forms.py index 9b880b6..734e185 100644 --- a/rental/forms.py +++ b/rental/forms.py @@ -54,14 +54,14 @@ class ReservationForm(forms.Form): # min_length=4, widget=forms.DateInput(attrs={ 'class': 'form-control form-control-lg form-control-a', - 'placeholder': 'Début *'}), + 'placeholder': '01/01/2020 *'}), required=True) end = forms.DateField( label='', input_formats=['%d/%m/%Y'], widget=forms.DateInput(attrs={ 'class': 'form-control form-control-lg form-control-a', - 'placeholder': 'Fin *'}), + 'placeholder': '31/12/2020 *'}), required=True) diff --git a/rental/tasks.py b/rental/tasks.py index 6635178..bab0bc7 100644 --- a/rental/tasks.py +++ b/rental/tasks.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals from celery import shared_task from django.core.mail import send_mail, mail_admins from villafleurie.settings import EMAIL_HOST_USER, BASE_DIR +from rental.bookings import build_calendar_api_service import os @@ -30,7 +31,6 @@ def send_notification(subject, name, message, template="activation"): html_path = os.path.join(BASE_DIR, 'rental/templates/rental/html/') with open(os.path.join(html_path, f"{template}.html"), 'r') as html: html_message = html.read() - mail_admins( f"{name} a envoyé un message", f"Sujet : {subject}\nMessage : {message}", @@ -39,8 +39,6 @@ def send_notification(subject, name, message, template="activation"): @shared_task -def send_quotation(reservation): +def send_quotation(name, email): """ Send quotation to customer """ - name = reservation.guest.name - email = list(reservation.guest.email) send_confirmation_mail(name, email, template="welcome") diff --git a/rental/views.py b/rental/views.py index 0e7995c..f0daa68 100644 --- a/rental/views.py +++ b/rental/views.py @@ -123,12 +123,11 @@ def reservation(request): end=end, price=price ) - send_quotation.delay(reservation) - update_calendar(reservation) # add to celery tasks too + send_quotation.delay(name, email) + update_calendar(reservation) context = { 'reservation': reservation } - return render(request, 'rental/merci.html', context) else: context = {'form': form} diff --git a/villafleurie/settings.py b/villafleurie/settings.py index 2d22415..fe4574f 100644 --- a/villafleurie/settings.py +++ b/villafleurie/settings.py @@ -8,6 +8,7 @@ ADMINS = [ ] SECRET_KEY = os.environ.get('SECRET_KEY') +# SECRET_KEY = "q00_4wqdc^n=7)p2lm)!gy&fms8md_b4#1aqysllvqq==2c9!$" if os.environ.get('ENV') == 'PRODUCTION': DEBUG = False @@ -147,5 +148,6 @@ EMAIL_SUBJECT_PREFIX = "[VillaFleurieGuadeloupe] " DEFAULT_FROM_EMAIL = "'Nilka, VillaFleurie' " EMAIL_HOST_USER = "location.villafleurie@gmail.com" EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') +# EMAIL_HOST_PASSWORD = "location229818" CELERY_BROKER_URL = "amqp://rabbitmq"