diff --git a/rental/admin.py b/rental/admin.py index 18550d1..90e09d6 100644 --- a/rental/admin.py +++ b/rental/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin + from rental.models.booking import Booking from rental.models.contact import Contact from rental.models.guest import Guest diff --git a/rental/enums.py b/rental/enums.py index 52e6e9f..32eb66a 100644 --- a/rental/enums.py +++ b/rental/enums.py @@ -3,6 +3,5 @@ from django.utils.translation import gettext_lazy as _ class PlaceNames(models.TextChoices): - T2 = "T2", _("T2") T3 = "T3", _("T3") diff --git a/rental/forms/booking.py b/rental/forms/booking.py index afdc177..6888892 100644 --- a/rental/forms/booking.py +++ b/rental/forms/booking.py @@ -1,4 +1,5 @@ from django import forms + from rental.models.booking import Booking from rental.models.place import Place from rental.enums import PlaceNames @@ -45,7 +46,6 @@ class BookingForm(forms.Form): message = forms.CharField( label='', - # max_length=100, min_length=4, widget=forms.Textarea(attrs={ 'class': 'form-control', @@ -58,8 +58,6 @@ class BookingForm(forms.Form): start = forms.DateField( label='', input_formats=['%d/%m/%Y'], - # max_length=100, - # min_length=4, widget=forms.DateInput(attrs={ 'class': 'form-control form-control-lg form-control-a', 'placeholder': '01/01/2020 *'}), diff --git a/rental/forms/contact.py b/rental/forms/contact.py index f538338..0f77957 100644 --- a/rental/forms/contact.py +++ b/rental/forms/contact.py @@ -34,7 +34,6 @@ class ContactForm(forms.Form): message = forms.CharField( label='', - # max_length=100, min_length=4, widget=forms.Textarea(attrs={ 'class': 'form-control', diff --git a/rental/models/booking.py b/rental/models/booking.py index b935846..1c2c0c3 100644 --- a/rental/models/booking.py +++ b/rental/models/booking.py @@ -1,5 +1,6 @@ from datetime import datetime from django.db import models + from rental.models.guest import Guest from rental.models.place import Place import rental.services.calendar as calendar diff --git a/rental/models/contact.py b/rental/models/contact.py index 0184300..45fd95f 100644 --- a/rental/models/contact.py +++ b/rental/models/contact.py @@ -1,4 +1,5 @@ from django.db import models + import rental.tasks.apiMailer as mailer # or gMailer diff --git a/rental/models/guest.py b/rental/models/guest.py index 06f7b05..bd63895 100644 --- a/rental/models/guest.py +++ b/rental/models/guest.py @@ -1,7 +1,6 @@ from django.db import models - class Guest(models.Model): class Meta: verbose_name = "Voyageur" diff --git a/rental/models/place.py b/rental/models/place.py index a1df42f..75eb4c8 100644 --- a/rental/models/place.py +++ b/rental/models/place.py @@ -1,4 +1,5 @@ from django.db import models + from rental.models.picture import Picture import rental.services.calendar as calendar diff --git a/rental/models/testimonial.py b/rental/models/testimonial.py index 3049d2a..f282568 100644 --- a/rental/models/testimonial.py +++ b/rental/models/testimonial.py @@ -1,4 +1,5 @@ from django.db import models + from rental.models.booking import Booking from rental.models.guest import Guest diff --git a/rental/services/calendar.py b/rental/services/calendar.py index 4631b09..c5bc7d3 100644 --- a/rental/services/calendar.py +++ b/rental/services/calendar.py @@ -1,11 +1,13 @@ import datetime +import os + +import pickle from google.auth.transport.requests import Request from google_auth_oauthlib.flow import InstalledAppFlow, Flow from googleapiclient.discovery import build -import os -import pickle -from villafleurie.settings import BASE_DIR from django.shortcuts import get_object_or_404 + +from villafleurie.settings import BASE_DIR from rental.models.guest import Guest import rental.models.place as m_place import rental.models.booking as m_booking @@ -31,13 +33,8 @@ def build_service(): else: SECRETS = os.path.join(BASE_DIR, 'rental/client_secrets.json') flow = InstalledAppFlow.from_client_secrets_file( - # flow = Flow.from_client_secrets_file( SECRETS, scopes=SCOPES, redirect_uri="http://localhost:8080/") creds = flow.run_local_server() - # creds = flow.run_console() - - # auth_url, _ = flow.authorization_url(prompt='consent') - # print(auth_url) with open('token.pickle', 'wb') as token: pickle.dump(creds, token) @@ -108,7 +105,7 @@ def synchronize(place): db_booking.guest = guest, db_booking.start = start, db_booking.end = end - # db_booking.price = price + def get_bookings_from_db(place): @@ -135,6 +132,7 @@ def check_availability(place, start_date, end_date): def update(reservation): """ push new reservation to master calendar """ # authenticate and build service + service, calendars = build_service() start = reservation.start.strftime('%Y-%m-%d') end = reservation.end.strftime('%Y-%m-%d') diff --git a/rental/tasks/apiMailer.py b/rental/tasks/apiMailer.py index 915c19d..53be4e0 100644 --- a/rental/tasks/apiMailer.py +++ b/rental/tasks/apiMailer.py @@ -1,7 +1,9 @@ from __future__ import absolute_import, unicode_literals from datetime import datetime -import requests + from celery import shared_task +import requests + from villafleurie.settings import EMAIL_HOST_USER, DEFAULT_FROM_EMAIL """ Mailer Service used to send messages using API WebHooks. @@ -12,7 +14,7 @@ from villafleurie.settings import EMAIL_HOST_USER, DEFAULT_FROM_EMAIL def send_notification(name, email, subject, message)->void def send_quotation(name, email)->void - """ +""" URL = "https://hooks.zapier.com/hooks/catch/4071838/o93celz/" @@ -30,8 +32,7 @@ def send_confirmation(name, email): } resp = requests.post(URL, data=payload) - print(resp.text) - print(resp.json) + @shared_task diff --git a/rental/tasks/gMailer.py b/rental/tasks/gMailer.py index 6a208e0..411f594 100644 --- a/rental/tasks/gMailer.py +++ b/rental/tasks/gMailer.py @@ -1,6 +1,8 @@ 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 @@ -20,34 +22,26 @@ def send_confirmation(name, email): """ Send confirmation message to customer """ subject = "Nous avons reçu votre message" message = f" Merci {name}, Bien reçu nous revenons vers vous rapidement !" - # html_path = os.path.join(BASE_DIR, 'rental/templates/rental/mails/') - # with open(os.path.join(html_path, f"{template}.html"), 'r') as html: - # html_message = html.read() send_mail( subject, message, EMAIL_HOST_USER, - [email] # , - # html_message=html_message.content - # html_message=html_message + [email] ) @shared_task def send_notification(name, email, subject, message): """ Send notification to admins """ - # html_path = os.path.join(BASE_DIR, 'rental/templates/rental/mails/') - # 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}\nDe : {name}, {email}\nMessage : {message}" - # html_message=html_message ) @shared_task def send_quotation(name, email): """ Send quotation to customer """ - send_confirmation_mail(name, email) # : , template="welcome") + send_confirmation_mail(name, email) diff --git a/rental/tests/booking.py b/rental/tests/booking.py index 1882fe7..c36d5d7 100644 --- a/rental/tests/booking.py +++ b/rental/tests/booking.py @@ -1,6 +1,8 @@ from datetime import datetime + from django.shortcuts import get_object_or_404 from django.test import TestCase + from rental.models.place import Place from rental.models.booking import Booking from rental.models.guest import Guest @@ -23,7 +25,6 @@ class BookingTestCase(TestCase): self.end = datetime(2019, 11, 20) def test_BookingPrice(self): - # place = Place.objects.get(name='TX') booking = Booking.objects.create_booking( place=self.place, start=self.start, diff --git a/rental/tests/calendar.py b/rental/tests/calendar.py index 64e781d..a9024a1 100644 --- a/rental/tests/calendar.py +++ b/rental/tests/calendar.py @@ -1,11 +1,9 @@ from django.test import TestCase + import rental.services.calendar as calendar class CalendarTestCase(TestCase): - def setUp(self): - pass def test_CalendarBuild(self): obj = calendar.build_service() - print(obj) \ No newline at end of file diff --git a/rental/urls.py b/rental/urls.py index e3b0d8d..de07096 100644 --- a/rental/urls.py +++ b/rental/urls.py @@ -1,5 +1,6 @@ from django.contrib.staticfiles.urls import static, staticfiles_urlpatterns from django.urls import path + from villafleurie import settings from rental.views import home, booking, contact, place diff --git a/rental/views/booking.py b/rental/views/booking.py index bbb4127..d3359d6 100644 --- a/rental/views/booking.py +++ b/rental/views/booking.py @@ -2,6 +2,7 @@ from django.core.exceptions import ValidationError from django.db import IntegrityError from django.shortcuts import render, get_object_or_404 from django.utils.translation import gettext_lazy as _ + from rental.forms.booking import BookingForm from rental.models.booking import Booking from rental.models.guest import Guest diff --git a/rental/views/contact.py b/rental/views/contact.py index 301df1e..e7ec447 100644 --- a/rental/views/contact.py +++ b/rental/views/contact.py @@ -1,4 +1,5 @@ from django.shortcuts import render + from rental.forms.contact import ContactForm from rental.models.contact import Contact diff --git a/rental/views/place.py b/rental/views/place.py index 4c50d87..d5b2ad2 100644 --- a/rental/views/place.py +++ b/rental/views/place.py @@ -1,5 +1,6 @@ from django.shortcuts import render, get_object_or_404 from django.utils.translation import gettext_lazy as _ + from rental.models.place import Place from rental.models.testimonial import Testimonial from rental.views.booking import handle_booking_form diff --git a/villafleurie/celery.py b/villafleurie/celery.py index 0584dc6..ed59e6e 100644 --- a/villafleurie/celery.py +++ b/villafleurie/celery.py @@ -11,4 +11,4 @@ app.autodiscover_tasks() @app.task(bind=True) def debug_task(self): - print('Request: {0!r}'.format(self.request)) + print(f'Request: {self.request!r}') diff --git a/villafleurie/wsgi.py b/villafleurie/wsgi.py index e7785a8..60eb6b1 100644 --- a/villafleurie/wsgi.py +++ b/villafleurie/wsgi.py @@ -1,5 +1,6 @@ import os from django.core.wsgi import get_wsgi_application + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'villafleurie.settings') application = get_wsgi_application()