diff --git a/.gitignore b/.gitignore index 2d7e6aa..f2ac9c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .venv postgresql -__pycache__ \ No newline at end of file +__pycache__ +db.env \ No newline at end of file diff --git a/app/hello.py b/app/hello.py new file mode 100644 index 0000000..f0d6792 --- /dev/null +++ b/app/hello.py @@ -0,0 +1,92 @@ +from datetime import datetime + +from urllib.parse import quote_plus +from sqlalchemy import create_engine, text + +from flask import Flask +from flask import request +from flask import render_template + +DB_USER = 'avsa_form' +DB_PASSWORD = '#4gvAwnUr5@MuZk9cYb!' +DB_HOST = 'avsa_form_db' +DB_PORT = '5432' +DB_NAME = 'avsa_form_db' +DB_TABLE = 'accounts' + +class user_data: + def __init__(self, first_name, last_name, phone_number, request_at, start_availability, end_availability, user_type): + self.first_name = first_name + self.last_name = last_name + self.phone_number = phone_number + self.request_at = request_at + self.start_availability = start_availability + self.end_availability = end_availability + self.user_type = user_type + +# new_data = current_data('lucas','royer','0612345678','2011-05-16 15:36:38','2011-05-16 15:36:38','2011-05-16 15:36:38','benevole') + +def insert_db(current_data): + # Connect to DB + engine = create_engine(f"postgresql+psycopg2://{DB_USER}:%s@{DB_HOST}:{DB_PORT}/{DB_NAME}" % quote_plus(DB_PASSWORD)) + conn = engine.connect() + + + + data = { + 'first_name': current_data.first_name, + 'last_name': current_data.last_name, + 'phone_number': current_data.phone_number, + 'request_at': current_data.request_at, + 'start_availability': current_data.start_availability, + 'end_availability': current_data.end_availability, + 'user_type': current_data.user_type, + } + + # SQL query + query=text(f"INSERT INTO {DB_TABLE} (first_name, last_name, phone_number, request_at, start_availability, end_availability, user_type) VALUES (:first_name, :last_name, :phone_number, :request_at, :start_availability, :end_availability, :user_type);") + + conn.execute(query, data) + conn.commit() + + +def create_app(): + app = Flask(__name__) + app.config.from_mapping( + SECRET_KEY='dev', + ) + + @app.route("/") + def accueil(): + return render_template('accueil.html') + + @app.route('/formulaire', methods=['GET']) + def formulaire(): + return render_template('formulaire.html', retry=False) + + @app.route('/resultat', methods=['POST']) + def resultat(): + if request.method == 'POST': + first_name = request.form['first_name'] + last_name = request.form['last_name'] + phone_number = request.form['phone_number'] + request_at = datetime.now().strftime("%m-%d-%Y %H:%M:%S") + + availability_date = request.form['availability_date'] + start_availability_h = request.form['start_availability_h'] + start_availability_m = request.form['start_availability_m'] + end_availability_h = request.form['end_availability_h'] + end_availability_m = request.form['end_availability_m'] + + start_availability = f'{availability_date} {start_availability_h}:{start_availability_m}:00' + end_availability = f'{availability_date} {end_availability_h}:{end_availability_m}:00' + user_type = request.form['user_type'] + current_data = user_data(first_name, last_name, phone_number, request_at, start_availability, end_availability, user_type) + + if any(value is None for value in current_data.__dict__.values()): + return render_template('formulaire.html', retry=True) + else: + insert_db(current_data) + return render_template('resultat.html', first_name=first_name, last_name=last_name, phone_number=phone_number, request_at=request_at, start_availability_h=start_availability_h, start_availability_m=start_availability_m, end_availability_h=end_availability_h, end_availability_m=end_availability_m, user_type=current_data.user_type) + + return app \ No newline at end of file diff --git a/templates/accueil.html b/app/templates/accueil.html similarity index 100% rename from templates/accueil.html rename to app/templates/accueil.html diff --git a/app/templates/calendar.html b/app/templates/calendar.html new file mode 100644 index 0000000..392c04f --- /dev/null +++ b/app/templates/calendar.html @@ -0,0 +1,405 @@ + + + + + +
+ + +| + + Sun + | ++ + Mon + | ++ + Tue + | ++ + Wed + | ++ + Thu + | ++ + Fri + | ++ + Sat + | +
|---|---|---|---|---|---|---|
|
+
+
+
+ 1
+
+
+
+
+
+ Meating
+
+
+ 12:00~14:00
+
+
+
+
+ Meating
+
+
+ 18:00~20:00
+
+
+ |
+
+
+
+
+ 2
+
+
+ |
+
+
+
+
+ 3
+
+
+ |
+
+
+
+
+ 4
+
+
+ |
+
+
+
+
+ 6
+
+
+ |
+
+
+
+
+ 7
+
+
+
+
+
+ Shopping
+
+
+ 12:00~14:00
+
+
+ |
+
+
+
+
+ 8
+
+
+ |
+
|
+
+
+
+ 9
+
+
+ |
+
+
+
+
+ 10
+
+
+ |
+
+
+
+
+ 12
+
+
+ |
+
+
+
+
+ 13
+
+
+ |
+
+
+
+
+ 14
+
+
+ |
+
+
+
+
+ 15
+
+
+ |
+
+
+
+
+ 16
+
+
+ |
+
|
+
+
+
+ 16
+
+
+ |
+
+
+
+
+ 17
+
+
+ |
+
+
+
+
+ 18
+
+
+ |
+
+
+
+
+ 19
+
+
+ |
+
+
+
+
+ 20
+
+
+ |
+
+
+
+
+ 21
+
+
+ |
+
+
+
+
+ 22
+
+
+ |
+
|
+
+
+
+ 23
+
+
+ |
+
+
+
+
+ 24
+
+
+ |
+
+
+
+
+ 25
+
+
+ |
+
+
+
+
+ 26
+
+
+ |
+
+
+
+
+ 27
+
+
+ |
+
+
+
+
+ 28
+
+
+ |
+
+
+
+
+ 29
+
+
+ |
+
|
+
+
+
+ 30
+
+
+ |
+
+
+
+
+ 31
+
+
+ |
+
+
+
+
+ 1
+
+
+ |
+
+
+
+
+ 2
+
+
+ |
+
+
+
+
+ 3
+
+
+ |
+
+
+
+
+ 4
+
+
+ |
+
+
+
+
+ 5
+
+
+ |
+