mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-06 02:16:47 +00:00
mailers modules added GMailer,APIMailer; inject Mailer service in views; Contact model created and registered;
This commit is contained in:
parent
a85bba3a11
commit
fd74cb80d7
8 changed files with 131 additions and 19 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
24
rental/migrations/0028_contact.py
Normal file
24
rental/migrations/0028_contact.py
Normal file
|
|
@ -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)),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
54
rental/tasks/apiMailer.py
Normal file
54
rental/tasks/apiMailer.py
Normal file
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12 col-lg-8">
|
||||
<div class="title-single-box">
|
||||
<h1 class="title-single">Message reçu!</h1>
|
||||
<h1 class="title-single">👌Message reçu!</h1>
|
||||
<span class="color-text-a"
|
||||
>Nous traitons votre demande et nous vous recontactons aussi
|
||||
rapidement que possible.
|
||||
|
|
|
|||
|
|
@ -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', {})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue