Prepare production

This commit is contained in:
Lucas
2024-05-12 14:58:27 +02:00
parent 950482dbaf
commit e06995c91b
13 changed files with 545 additions and 108 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.venv .venv
postgresql postgresql
__pycache__ __pycache__
db.env

92
app/hello.py Normal file
View File

@@ -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

405
app/templates/calendar.html Normal file
View File

@@ -0,0 +1,405 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>tailwind Calendar</title>
</head>
<body class="bg-gray-200">
<div class="container mx-auto mt-10">
<div class="wrapper bg-white rounded shadow w-full ">
<div class="header flex justify-between border-b p-2">
<span class="text-lg font-bold">
2020 July
</span>
<div class="buttons">
<button class="p-1">
<svg width="1em" fill="gray" height="1em" viewBox="0 0 16 16" class="bi bi-arrow-left-circle" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
<path fill-rule="evenodd" d="M8.354 11.354a.5.5 0 0 0 0-.708L5.707 8l2.647-2.646a.5.5 0 1 0-.708-.708l-3 3a.5.5 0 0 0 0 .708l3 3a.5.5 0 0 0 .708 0z" />
<path fill-rule="evenodd" d="M11.5 8a.5.5 0 0 0-.5-.5H6a.5.5 0 0 0 0 1h5a.5.5 0 0 0 .5-.5z" />
</svg>
</button>
<button class="p-1">
<svg width="1em" fill="gray" height="1em" viewBox="0 0 16 16" class="bi bi-arrow-right-circle" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
<path fill-rule="evenodd" d="M7.646 11.354a.5.5 0 0 1 0-.708L10.293 8 7.646 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0z" />
<path fill-rule="evenodd" d="M4.5 8a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5z" />
</svg>
</button>
</div>
</div>
<table class="w-full">
<thead>
<tr>
<th class="p-2 border-r h-10 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 xl:text-sm text-xs">
<span class="xl:block lg:block md:block sm:block hidden">Sunday</span>
<span class="xl:hidden lg:hidden md:hidden sm:hidden block">Sun</span>
</th>
<th class="p-2 border-r h-10 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 xl:text-sm text-xs">
<span class="xl:block lg:block md:block sm:block hidden">Monday</span>
<span class="xl:hidden lg:hidden md:hidden sm:hidden block">Mon</span>
</th>
<th class="p-2 border-r h-10 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 xl:text-sm text-xs">
<span class="xl:block lg:block md:block sm:block hidden">Tuesday</span>
<span class="xl:hidden lg:hidden md:hidden sm:hidden block">Tue</span>
</th>
<th class="p-2 border-r h-10 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 xl:text-sm text-xs">
<span class="xl:block lg:block md:block sm:block hidden">Wednesday</span>
<span class="xl:hidden lg:hidden md:hidden sm:hidden block">Wed</span>
</th>
<th class="p-2 border-r h-10 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 xl:text-sm text-xs">
<span class="xl:block lg:block md:block sm:block hidden">Thursday</span>
<span class="xl:hidden lg:hidden md:hidden sm:hidden block">Thu</span>
</th>
<th class="p-2 border-r h-10 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 xl:text-sm text-xs">
<span class="xl:block lg:block md:block sm:block hidden">Friday</span>
<span class="xl:hidden lg:hidden md:hidden sm:hidden block">Fri</span>
</th>
<th class="p-2 border-r h-10 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 xl:text-sm text-xs">
<span class="xl:block lg:block md:block sm:block hidden">Saturday</span>
<span class="xl:hidden lg:hidden md:hidden sm:hidden block">Sat</span>
</th>
</tr>
</thead>
<tbody>
<tr class="text-center h-20">
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300 ">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">1</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer">
<div class="event bg-purple-400 text-white rounded p-1 text-sm mb-1">
<span class="event-name">
Meating
</span>
<span class="time">
12:00~14:00
</span>
</div>
<div class="event bg-purple-400 text-white rounded p-1 text-sm mb-1">
<span class="event-name">
Meating
</span>
<span class="time">
18:00~20:00
</span>
</div>
</div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">2</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">3</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">4</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">6</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-hidden transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">7</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer">
<div class="event bg-blue-400 text-white rounded p-1 text-sm mb-1">
<span class="event-name">
Shopping
</span>
<span class="time">
12:00~14:00
</span>
</div>
</div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500 text-sm">8</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
</tr>
<!-- line 1 -->
<tr class="text-center h-20">
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">9</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">10</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">12</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">13</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">14</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">15</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500 text-sm">16</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
</tr>
<!-- line 1 -->
<!-- line 2 -->
<tr class="text-center h-20">
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">16</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">17</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">18</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">19</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">20</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">21</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500 text-sm">22</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
</tr>
<!-- line 2 -->
<!-- line 3 -->
<tr class="text-center h-20">
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">23</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">24</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">25</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">26</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">27</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">28</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500 text-sm">29</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
</tr>
<!-- line 3 -->
<!-- line 4 -->
<tr class="text-center h-20">
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">30</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">31</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border bg-gray-100 p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">1</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border bg-gray-100 p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">2</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border bg-gray-100 p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">3</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border bg-gray-100 p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500">4</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
<td class="border bg-gray-100 p-1 h-40 xl:w-40 lg:w-30 md:w-30 sm:w-20 w-10 overflow-auto transition cursor-pointer duration-500 ease hover:bg-gray-300">
<div class="flex flex-col h-40 mx-auto xl:w-40 lg:w-30 md:w-30 sm:w-full w-10 mx-auto overflow-hidden">
<div class="top h-5 w-full">
<span class="text-gray-500 text-sm">5</span>
</div>
<div class="bottom flex-grow h-30 py-1 w-full cursor-pointer"></div>
</div>
</td>
</tr>
<!-- line 4 -->
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@@ -1,21 +0,0 @@
#version: '3'
services:
db:
image: postgres:13.1
container_name: avsa_form_db
restart: always
volumes:
- ./postgresql:/var/lib/postgresql/data
env_file:
- db.env
networks:
- avsa_form
flask:
image: python:3.11.8-alpine
networks:
avsa_form:
external: true
#reverse-proxy:

View File

@@ -1,85 +0,0 @@
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()
app = Flask(__name__)
@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)

6
production/Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM python:3.11.8-alpine
# Prod depedencies
RUN pip install flask psycopg2-binary sqlalchemy waitress
WORKDIR /app

View File

@@ -1,3 +1,3 @@
POSTGRES_USER=avsa_form POSTGRES_USER=avsa_form
POSTGRES_PASSWORD=#4gvAwnUr5@MuZk9cYb! POSTGRES_PASSWORD=
POSTGRES_DB=avsa_form_db POSTGRES_DB=avsa_form_db

3
production/db-public.env Normal file
View File

@@ -0,0 +1,3 @@
POSTGRES_USER=avsa_form
POSTGRES_PASSWORD=
POSTGRES_DB=avsa_form_db

View File

@@ -0,0 +1,36 @@
services:
app:
context: .
dockerfile: Dockerfile
container_name: avsa_form_app
restart: always
volumes:
- ../app:/app
command: waitress-serve --call 'hello:create_app'
env_file:
- app.env
- db.env
networks:
- reverse-proxy
- avsa_form
db:
image: postgres:13.1
container_name: avsa_form_db
restart: always
volumes:
- ./postgresql:/var/lib/postgresql/data
env_file:
- db.env
networks:
- avsa_form
networks:
avsa_form:
reverse-proxy:
external: true