diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 489d709..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 2 -jobs: - build: - machine: true - steps: - - checkout - - - run: | - docker-compose up - - - run: | - docker login --username=$HEROKU_USERNAME --password=$HEROKU_API_KEY registry.heroku.com - docker tag villafleurie registry.heroku.com/$HEROKU_APP_NAME/web - docker push registry.heroku.com/$HEROKU_APP_NAME/web - curl https://cli-assets.heroku.com/install.sh | sh - heroku container:release web -a $HEROKU_APP_NAME diff --git a/.gitignore b/.gitignore index 3be3345..56365d6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ villafleurie/staticfiles/ .vscode/ rental/client_secrets.json token.pickle -prod.env +*.env *.tar \ No newline at end of file diff --git a/README.md b/README.md index cecaa98..066cc7e 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,7 @@ Le visiteur doit pouvoir : - Envoyer devis réservation par mail et notification aux hôtes (put it in a background process, personnaliser les htmails : contact, admin et réservation) - Ajout page/module de paiement - ajouter les témoignages depuis Booking, AirBnb, ajouter le lien -- changer la couleur des liens hypertextes - changer l'adresse de l'admin, personnaliser le back-end (design et les infos displayed per model) -- ajouter un diaporama en bas de page de location ? - factoriser le code de réservation - formulaire de réservation : les apparts sont hard codés rendre ça dynamique (use choicefields) \_ nettoyer les statics files. Garder que les définitions utiles @@ -118,6 +116,8 @@ Le visiteur doit pouvoir : - Internationalisation - Connect to domain name - 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. +- Vider le contenu du folder root ? ## BUGS diff --git a/docker-compose.yml b/docker-compose.yml index 97f76ab..a47e1d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,31 @@ version: "3" +volumes: + static_files: + services: db: image: postgres + web: build: . - # command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py loaddata villafleurie.json && python manage.py runserver 0.0.0.0:8000" - command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py loaddata villafleurie.json && gunicorn -w 4 villafleurie.wsgi -b 0.0.0.0:8000" - # command: gunicorn villafleurie.wsgi -b 0.0.0.0:8000 # Production server more secure + 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 ports: - "8000:8000" depends_on: - db env_file: prod.env + + nginx: + # image: nginx + build: + context: . + dockerfile: nginx/Dockerfile + ports: + - 80:80 + volumes: + - static_files:/static_files diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..4a65074 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,5 @@ +FROM nginx + +RUN rm /etc/nginx/conf.d/default.conf + +COPY nginx/villafleurie.conf /etc/nginx/conf.d/ \ No newline at end of file diff --git a/nginx/villafleurie.conf b/nginx/villafleurie.conf new file mode 100644 index 0000000..840bfc6 --- /dev/null +++ b/nginx/villafleurie.conf @@ -0,0 +1,16 @@ +server { + listen 80; + server_name localhost; + access_log /var/log/nginx/example.log; + + location static/ { + autoindex off; + alias /static_files/; + } + + location / { + proxy_pass http://127.0.0.1:8000; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + } +} \ No newline at end of file diff --git a/rental/bookings.py b/rental/bookings.py index 73042f8..42458bd 100644 --- a/rental/bookings.py +++ b/rental/bookings.py @@ -81,7 +81,10 @@ def synchronize_calendars(place): place = get_object_or_404(Place, name=place.name) price = get_reservation_price( - place, reservation['start'], reservation['end']) + place, + reservation['start'], + reservation['end'] + ) start = reservation['start'] end = reservation['end'] diff --git a/rental/static/rental/contactform/contactform.js b/rental/static/rental/contactform/contactform.js deleted file mode 100644 index 86b77e0..0000000 --- a/rental/static/rental/contactform/contactform.js +++ /dev/null @@ -1,118 +0,0 @@ -jQuery(document).ready(function($) { - "use strict"; - - //Contact - $('form.contactForm').submit(function() { - var f = $(this).find('.form-group'), - ferror = false, - emailExp = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i; - - f.children('input').each(function() { // run all inputs - - var i = $(this); // current input - var rule = i.attr('data-rule'); - - if (rule !== undefined) { - var ierror = false; // error flag for current input - var pos = rule.indexOf(':', 0); - if (pos >= 0) { - var exp = rule.substr(pos + 1, rule.length); - rule = rule.substr(0, pos); - } else { - rule = rule.substr(pos + 1, rule.length); - } - - switch (rule) { - case 'required': - if (i.val() === '') { - ferror = ierror = true; - } - break; - - case 'minlen': - if (i.val().length < parseInt(exp)) { - ferror = ierror = true; - } - break; - - case 'email': - if (!emailExp.test(i.val())) { - ferror = ierror = true; - } - break; - - case 'checked': - if (! i.is(':checked')) { - ferror = ierror = true; - } - break; - - case 'regexp': - exp = new RegExp(exp); - if (!exp.test(i.val())) { - ferror = ierror = true; - } - break; - } - i.next('.validation').html((ierror ? (i.attr('data-msg') !== undefined ? i.attr('data-msg') : 'wrong Input') : '')).show('blind'); - } - }); - f.children('textarea').each(function() { // run all inputs - - var i = $(this); // current input - var rule = i.attr('data-rule'); - - if (rule !== undefined) { - var ierror = false; // error flag for current input - var pos = rule.indexOf(':', 0); - if (pos >= 0) { - var exp = rule.substr(pos + 1, rule.length); - rule = rule.substr(0, pos); - } else { - rule = rule.substr(pos + 1, rule.length); - } - - switch (rule) { - case 'required': - if (i.val() === '') { - ferror = ierror = true; - } - break; - - case 'minlen': - if (i.val().length < parseInt(exp)) { - ferror = ierror = true; - } - break; - } - i.next('.validation').html((ierror ? (i.attr('data-msg') != undefined ? i.attr('data-msg') : 'wrong Input') : '')).show('blind'); - } - }); - if (ferror) return false; - else var str = $(this).serialize(); - var action = $(this).attr('action'); - if( ! action ) { - action = 'contactform/contactform.php'; - } - $.ajax({ - type: "POST", - url: action, - data: str, - success: function(msg) { - // alert(msg); - if (msg == 'OK') { - $("#sendmessage").addClass("show"); - $("#errormessage").removeClass("show"); - $('.contactForm').find("input, textarea").val(""); - } else { - $("#sendmessage").removeClass("show"); - $("#errormessage").addClass("show"); - $('#errormessage').html(msg); - } - - } - }); - return false; - }); - -}); diff --git a/rental/templates/rental/base.html b/rental/templates/rental/base.html index 63d14a7..46cd606 100644 --- a/rental/templates/rental/base.html +++ b/rental/templates/rental/base.html @@ -214,7 +214,6 @@ - diff --git a/villafleurie/settings.py b/villafleurie/settings.py index 83fd000..3e0abe1 100644 --- a/villafleurie/settings.py +++ b/villafleurie/settings.py @@ -1,4 +1,3 @@ -# import dj_database_url import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) @@ -9,15 +8,10 @@ ADMINS = [ ] SECRET_KEY = os.environ.get('SECRET_KEY') -# SECRET_KEY = 'q00_4wqdc^n=7)p2lm)!gy&fms8md_b4#1aqysllvqq==2c9!$' if os.environ.get('ENV') == 'PRODUCTION': DEBUG = False # STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' - # Heroku - # db_from_env = dj_database_url.config(conn_max_age=500) - # DATABASES['default'].update(db_from_env) - # Docker DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', @@ -28,16 +22,19 @@ 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) + # 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_files/" CSRF_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True CONN_MAX_AGE = 500 + + else: DEBUG = True DATABASES = { @@ -55,17 +52,22 @@ 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') + # PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) + # STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') +ALLOWED_HOSTS = [ + '127.0.0.1', + '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) -if os.environ.get('ENV') == 'PRODUCTION': - ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOSTS')] -else: - ALLOWED_HOSTS = [ - '127.0.0.1', - 'localhost' - ] INSTALLED_APPS = [ 'django.contrib.admin', @@ -81,7 +83,7 @@ SITE_ID = 1 MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', - 'whitenoise.middleware.WhiteNoiseMiddleware', + # 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -146,4 +148,3 @@ EMAIL_SUBJECT_PREFIX = "[VillaFleurieGuadeloupe] " DEFAULT_FROM_EMAIL = "'Nilka, VillaFleurie' " EMAIL_HOST_USER = "location.villafleurie@gmail.com" EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') -EMAIL_HOST_PASSWORD = "location229818"