diff --git a/README.md b/README.md index 1a92cc1..65f5446 100644 --- a/README.md +++ b/README.md @@ -117,10 +117,13 @@ 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. - [x] Vider le contenu du folder root ? -- [ ] Pages confirmation message contact envoyé, reservations réussies ou non (expliquer pourquoi) +- [x] Pages confirmation message contact envoyé, +- [ ]reservations réussies ou non (expliquer pourquoi) - [ ] SSL certificate - [ ] Cookie bar - [ ] Booking refs on landing page +- [ ] CD/CI build flow from master to Production +- [ ] configure zapier webhooks ## BUGS diff --git a/rental/admin.py b/rental/admin.py index 146354d..25a7fc3 100644 --- a/rental/admin.py +++ b/rental/admin.py @@ -1,9 +1,10 @@ from django.contrib import admin -from .models import Testimonial, Reservation, Guest, Place, Image +from .models import Testimonial, Reservation, Guest, Place, Image, Contact -admin.site.register(Place) +admin.site.register(Contact) admin.site.register(Guest) +admin.site.register(Image) +admin.site.register(Place) admin.site.register(Reservation) admin.site.register(Testimonial) -admin.site.register(Image) diff --git a/rental/migrations/0028_contact.py b/rental/migrations/0028_contact.py new file mode 100644 index 0000000..a11faae --- /dev/null +++ b/rental/migrations/0028_contact.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.4 on 2020-03-28 07:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rental', '0027_auto_20191209_1831'), + ] + + operations = [ + migrations.CreateModel( + name='Contact', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50)), + ('email', models.EmailField(max_length=50)), + ('subject', models.EmailField(max_length=50)), + ('message', models.TextField(max_length=50)), + ('date', models.DateTimeField(auto_now_add=True)), + ], + ), + ] diff --git a/rental/models.py b/rental/models.py index d2b983f..f43a093 100644 --- a/rental/models.py +++ b/rental/models.py @@ -73,3 +73,15 @@ class Testimonial(models.Model): Guest, on_delete=models.CASCADE, blank=True, null=True) reservation = models.OneToOneField( Reservation, on_delete=models.CASCADE, blank=True, null=True) + + +class Contact(models.Model): + + def __str__(self): + return f"Message de {self.name}, le {self.date}" + + name = models.CharField(max_length=50) + email = models.EmailField(max_length=50) + subject = models.EmailField(max_length=50) + message = models.TextField(max_length=50) + date = models.DateTimeField(auto_now_add=True) diff --git a/rental/tasks/apiMailer.py b/rental/tasks/apiMailer.py new file mode 100644 index 0000000..63ebe61 --- /dev/null +++ b/rental/tasks/apiMailer.py @@ -0,0 +1,54 @@ +from __future__ import absolute_import, unicode_literals +from celery import shared_task +from villafleurie.settings import EMAIL_HOST_USER, DEFAULT_FROM_EMAIL +import requests + +""" Mailer Service used to send messages using API WebHooks. + All Mailers must implement the following methods: + + def send_confirmation(name, email)->void + + def send_notification(name, email, subject, message)->void + + def send_quotation(name, email)->void + """ + +URL = "https://hooks.zapier.com/hooks/catch/4071838/o93celz/" + + +@shared_task +def send_confirmation(name, email): + """ Send confirmation message to customer """ + + payload = { + "mail_to": email, + "from_name": DEFAULT_FROM_EMAIL, + "reply_to": EMAIL_HOST_USER, + "subject": f"[VillaFleurie] - {name}, nous avons reçu votre message", + "body": f"Merci {name}, nous avons bien reçu votre message, nous revenons vers vous rapidement !" + } + + resp = requests.post(URL, data=payload) + print(resp.text) + print(resp.json) + + +@shared_task +def send_notification(name, email, subject, message, date): + """ Send notification to admins """ + + payload = { + "mail_to": EMAIL_HOST_USER, + "from_name": DEFAULT_FROM_EMAIL, + "reply_to": EMAIL_HOST_USER, + "subject": f"{name} a envoyé un message", + "body": f"Sujet : {subject}\nDe : {name}, {email}\nLe : {date}\nMessage : {message}" + } + + resp = requests.post(URL, data=payload) + + +@shared_task +def send_quotation(name, email): + """ Send quotation to customer """ + send_confirmation(name, email) diff --git a/rental/tasks.py b/rental/tasks/gMailer.py similarity index 71% rename from rental/tasks.py rename to rental/tasks/gMailer.py index 23ac800..6a208e0 100644 --- a/rental/tasks.py +++ b/rental/tasks/gMailer.py @@ -1,14 +1,22 @@ from __future__ import absolute_import, unicode_literals from celery import shared_task from django.core.mail import send_mail, mail_admins -from django.shortcuts import render -from villafleurie.settings import EMAIL_HOST_USER, BASE_DIR -from rental.bookings import build_calendar_api_service -import os +from villafleurie.settings import EMAIL_HOST_USER + + +""" Mailer Service used to send messages using Gmail. + All Mailers must implement the following methods: + + def send_confirmation(name, email)->void + + def send_notification(name, email, subject, message)->void + + def send_quotation(name, email)->void + """ @shared_task -def send_confirmation_mail(name, email): # , template="ticket"): +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 !" @@ -27,14 +35,14 @@ def send_confirmation_mail(name, email): # , template="ticket"): @shared_task -def send_notification(subject, name, message): # , template="activation"): +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}\nMessage : {message}" # , + f"Sujet : {subject}\nDe : {name}, {email}\nMessage : {message}" # html_message=html_message ) diff --git a/rental/templates/rental/contact_merci.html b/rental/templates/rental/contact_merci.html index 0b04b44..1804fe8 100644 --- a/rental/templates/rental/contact_merci.html +++ b/rental/templates/rental/contact_merci.html @@ -5,7 +5,7 @@
-

Message reçu!

+

👌Message reçu!

Nous traitons votre demande et nous vous recontactons aussi rapidement que possible. diff --git a/rental/views.py b/rental/views.py index f1a20d7..0325dde 100644 --- a/rental/views.py +++ b/rental/views.py @@ -7,7 +7,9 @@ from .forms import ReservationForm, ContactForm from django.db import IntegrityError from rental.pricing import get_reservation_price from rental.bookings import check_availability, synchronize_calendars, update_calendar -from rental.tasks import send_confirmation_mail, send_notification, send_quotation +# send_confirmation_mail, send_notification, send_quotation +from rental.tasks.apiMailer import * # gMailer +from rental.models import Contact def index(request): @@ -118,13 +120,21 @@ def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): - name = form.cleaned_data['name'] - email = form.cleaned_data['email'] - subject = form.cleaned_data['subject'] - message = form.cleaned_data['message'] + contact = Contact.objects.create( + name=form.cleaned_data['name'], + email=form.cleaned_data['email'], + subject=form.cleaned_data['subject'], + message=form.cleaned_data['message'] + ) - send_confirmation_mail.delay(name, email) - send_notification.delay(subject, name, message) + send_confirmation.delay(contact.name, contact.email) + send_notification.delay( + contact.name, + contact.email, + contact.subject, + contact.message, + contact.date + ) return render(request, 'rental/contact_merci.html', {})