mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-06 02:16:47 +00:00
chore: clean code
This commit is contained in:
parent
f4f353a44c
commit
e6235e72cc
20 changed files with 32 additions and 35 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,6 +3,5 @@ from django.utils.translation import gettext_lazy as _
|
|||
|
||||
|
||||
class PlaceNames(models.TextChoices):
|
||||
|
||||
T2 = "T2", _("T2")
|
||||
T3 = "T3", _("T3")
|
||||
|
|
|
|||
|
|
@ -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 *'}),
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django.db import models
|
||||
|
||||
import rental.tasks.apiMailer as mailer # or gMailer
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
|
||||
class Guest(models.Model):
|
||||
class Meta:
|
||||
verbose_name = "Voyageur"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django.db import models
|
||||
|
||||
from rental.models.picture import Picture
|
||||
import rental.services.calendar as calendar
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django.db import models
|
||||
|
||||
from rental.models.booking import Booking
|
||||
from rental.models.guest import Guest
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
from rental.forms.contact import ContactForm
|
||||
from rental.models.contact import Contact
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}')
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue