diff --git a/.gitignore b/.gitignore index 56365d6..f0a3a69 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,12 @@ +.DS_Store +.vscode/ env/ __pycache__/ rental/__pycache__/ rental/migrations/ villafleurie/__pycache__/ villafleurie/staticfiles/ -.DS_Store -.vscode/ +villafleurie/static_files/ rental/client_secrets.json token.pickle *.env diff --git a/docker-compose.yml b/docker-compose.yml index a53d4b6..6eefa28 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ version: "3" volumes: static_files: + media: services: db: @@ -10,10 +11,10 @@ services: 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" - # container_name: villafleurie volumes: - .:/villafleurie - static_files:/static_files + - media:/villafleurie/media ports: - "8000:8000" depends_on: @@ -21,7 +22,6 @@ services: env_file: prod.env nginx: - # image: nginx build: context: . dockerfile: nginx/Dockerfile @@ -29,5 +29,6 @@ services: - 80:80 volumes: - static_files:/static_files + - media:/media depends_on: - web diff --git a/manage.py b/manage.py index c699d16..9c23ec5 100755 --- a/manage.py +++ b/manage.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" +""" Django's command-line utility for administrative tasks """ import os import sys diff --git a/nginx/villafleurie.conf b/nginx/villafleurie.conf index e32e3aa..2181713 100644 --- a/nginx/villafleurie.conf +++ b/nginx/villafleurie.conf @@ -3,11 +3,16 @@ server { server_name localhost; access_log /var/log/nginx/example.log; - location static/ { + location /static/ { autoindex off; alias /static_files/; } + location /media/ { + autoindex off; + alias /media/; + } + location / { proxy_pass http://web:8000; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/rental/bookings.py b/rental/bookings.py index 42458bd..232a437 100644 --- a/rental/bookings.py +++ b/rental/bookings.py @@ -12,9 +12,8 @@ from villafleurie.settings import BASE_DIR def build_calendar_api_service(): - """ - Build Google Calendar API service and returns calendar list and service - """ + """ Build Google Calendar API service and returns calendar list and service """ + creds = None # If modifying these scopes, delete the file token.pickle. SCOPES = ['https://www.googleapis.com/auth/calendar'] @@ -72,13 +71,11 @@ def get_calendar_reservations(place): def synchronize_calendars(place): - """ - Get a complete list of existing bookings in calendar + """ Get a complete list of existing bookings in calendar Creates reservation if not in db, update if already in db - Delete from db reservation deleted from cal - """ - reservation = get_calendar_reservations(place) + Delete from db reservation deleted from cal """ + reservation = get_calendar_reservations(place) place = get_object_or_404(Place, name=place.name) price = get_reservation_price( place, @@ -115,10 +112,9 @@ def synchronize_calendars(place): def get_bookings(place): - """ - Synchronize with Master calendar via a call to synchronize_calendar - Returns a list of all related place reservations - """ + """ Synchronize with Master calendar via a call to synchronize_calendar + Returns a list of all related place reservations """ + synchronize_calendars(place) booked_dates = Reservation.objects.filter(place=place) # if booking.place.name == f"{place.name}"] @@ -126,9 +122,8 @@ def get_bookings(place): def check_availability(place, start_date, end_date): - """ - check if the related place is available during a given period - """ + """ check if the related place is available during a given period """ + bookings = get_bookings(place) for booking in bookings: if (booking.start <= start_date <= booking.end) or (booking.start <= end_date <= booking.end): diff --git a/rental/mailing.py b/rental/mailing.py index 7f9fdd6..75967fe 100644 --- a/rental/mailing.py +++ b/rental/mailing.py @@ -8,9 +8,7 @@ import os # @app.task def send_confirmation_mail(name, email, template="ticket"): - """ - Send confirmation message to customer - """ + """ Send confirmation message to customer """ subject = "Nous avons reçu votre message" message = f" Merci {name}, Bien reçu nous revenons vers vous rapidement ! - HtmlMessage" @@ -28,9 +26,7 @@ def send_confirmation_mail(name, email, template="ticket"): def send_notification(subject, name, message, template="activation"): - """ - Send notification to admins - """ + """ Send notification to admins """ 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() @@ -43,9 +39,7 @@ def send_notification(subject, name, message, template="activation"): def send_quotation(reservation): - """ - Send quotation to customer - """ + """ Send quotation to customer """ name = reservation.guest.name email = list(reservation.guest.email) send_confirmation_mail(name, email, template="welcome") diff --git a/rental/pricing.py b/rental/pricing.py index 25ab6e5..5b38d17 100644 --- a/rental/pricing.py +++ b/rental/pricing.py @@ -2,9 +2,7 @@ from datetime import datetime def get_reservation_price(place, start, end): - """ - Compute booking price as a function of place and dates - """ + """ Compute booking price as a function of place and dates """ if type(start) == str: start = datetime.strptime(start, '%Y-%m-%d') if type(end) == str: diff --git a/requirements.txt b/requirements.txt index 304998a..73c472e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ asgiref==3.2.3 astroid==2.3.3 -autopep8==1.4.4 beautifulsoup4==4.8.1 cachetools==3.1.1 certifi==2019.11.28 diff --git a/villafleurie/settings.py b/villafleurie/settings.py index d4d1c54..fe72261 100644 --- a/villafleurie/settings.py +++ b/villafleurie/settings.py @@ -11,7 +11,6 @@ SECRET_KEY = os.environ.get('SECRET_KEY') if os.environ.get('ENV') == 'PRODUCTION': DEBUG = False - # STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', @@ -22,19 +21,13 @@ if os.environ.get('ENV') == 'PRODUCTION': 'ATOMIC_REQUESTS': True } } - # PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) - # STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') - # STATIC_TMP = os.path.join(PROJECT_ROOT, 'static') - # # Extra places for collectstatic to find static files. - # STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static'),) - # os.makedirs(STATIC_TMP, exist_ok=True) - # os.makedirs(STATIC_ROOT, exist_ok=True) - STATIC_ROOT = "/static/" + + PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) + # STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static') CSRF_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True CONN_MAX_AGE = 500 - else: DEBUG = True DATABASES = { @@ -52,8 +45,6 @@ else: } } STATICFILES_DIRS = [os.path.join(BASE_DIR, "rental", "static", "rental"), ] - # PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) - # STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') ALLOWED_HOSTS = [ '0.0.0.0', @@ -61,15 +52,6 @@ ALLOWED_HOSTS = [ 'localhost' ] -# PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) -# STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') -# STATIC_TMP = os.path.join(PROJECT_ROOT, 'static') -# # Extra places for collectstatic to find static files. -# STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static'),) -# os.makedirs(STATIC_TMP, exist_ok=True) -# os.makedirs(STATIC_ROOT, exist_ok=True) - - INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', @@ -84,7 +66,6 @@ SITE_ID = 1 MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', - # 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -120,7 +101,6 @@ TEMPLATES = [ }, ] - WSGI_APPLICATION = 'villafleurie.wsgi.application' AUTH_PASSWORD_VALIDATORS = [ @@ -137,10 +117,11 @@ USE_L10N = True USE_TZ = True STATIC_URL = '/static/' +STATIC_ROOT = "/static_files/" - -MEDIA_ROOT = os.path.join(BASE_DIR, "media") +# MEDIA_ROOT = os.path.join(BASE_DIR, "media") MEDIA_URL = '/media/' +MEDIA_ROOT = '/media/' EMAIL_HOST = "smtp.gmail.com" EMAIL_USE_TLS = True diff --git a/villafleurie/wsgi.py b/villafleurie/wsgi.py index 73aa094..e7785a8 100644 --- a/villafleurie/wsgi.py +++ b/villafleurie/wsgi.py @@ -1,16 +1,5 @@ -""" -WSGI config for villafleurie project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ -""" - import os from django.core.wsgi import get_wsgi_application - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'villafleurie.settings') - application = get_wsgi_application()