Compare commits
11 Commits
1b83098fd0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 504d237405 | |||
| 6696bcc4e7 | |||
| 32a1458218 | |||
| 4697086f86 | |||
| c4b9e5f360 | |||
| 0a9934b889 | |||
| 8ad1650079 | |||
| 6e50013a84 | |||
| dba9a7690d | |||
| 319d237e5d | |||
| af6515e55f |
@@ -1,8 +1,11 @@
|
||||
from flask import Flask, render_template, request, redirect, url_for, jsonify
|
||||
import sqlite3
|
||||
import re
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
pattern = re.compile(r"^(?:[01]\d|2[0-3]):[0-5]\d$") # Regex "XX:XX"
|
||||
|
||||
DB_PATH = "data.db"
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
@@ -16,6 +19,15 @@ CREATE TABLE IF NOT EXISTS items (
|
||||
noshutdown INTEGER DEFAULT 0
|
||||
)
|
||||
""")
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS val (
|
||||
default_time TEXT NOT NULL DEFAULT '21:00'
|
||||
)
|
||||
""")
|
||||
cursor.execute("SELECT COUNT(*) FROM val")
|
||||
count = cursor.fetchone()[0]
|
||||
if count == 0:
|
||||
cursor.execute("INSERT INTO val (default_time) VALUES (?)", ('21:00',))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -30,9 +42,11 @@ def mainpage():
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT name, time, noshutdown FROM items ORDER BY name")
|
||||
items = cursor.fetchall()
|
||||
cursor.execute("SELECT default_time FROM val")
|
||||
default_time_row = cursor.fetchone()
|
||||
default_time = default_time_row[0] if default_time_row else '21:00'
|
||||
conn.close()
|
||||
print(items)
|
||||
return render_template('index.html', title='BS Shutdown', items=items)
|
||||
return render_template('index.html', title='BS Shutdown', items=items, default_time=default_time)
|
||||
|
||||
@app.route('/submit', methods =['POST'])
|
||||
def submit():
|
||||
@@ -45,6 +59,9 @@ def submit():
|
||||
return redirect(url_for("mainpage"))
|
||||
if noshutdown == 1:
|
||||
time_value = 'None'
|
||||
if time_value != 'None':
|
||||
if bool(pattern.match(time_value)) is not True:
|
||||
return redirect(url_for("mainpage"))
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT 1 FROM items WHERE name = ?', (value,))
|
||||
@@ -57,6 +74,18 @@ def submit():
|
||||
conn.close()
|
||||
return redirect(url_for("mainpage"))
|
||||
|
||||
@app.route("/submit-default", methods=["POST"])
|
||||
def submit_default():
|
||||
time_value = request.form.get("default-time")
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
if bool(pattern.match(time_value)) is not True:
|
||||
return redirect(url_for("mainpage"))
|
||||
cursor.execute("UPDATE val SET default_time = ?", (time_value,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return redirect(url_for("mainpage"))
|
||||
|
||||
@app.route("/delete", methods=["POST"])
|
||||
def delete():
|
||||
value = request.form.get("item_name")
|
||||
|
||||
@@ -42,7 +42,10 @@
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if title=='BG Shutdown' %}active{% endif %}" href="{{ url_for('mainpage') }}">Accueil</a>
|
||||
<a class="nav-link {% if title=='BS Shutdown' %}active{% endif %}" href="{{ url_for('mainpage') }}">Accueil</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if title=='BG Shutdown' %}active{% endif %}" href="{{ url_for('mainpage') }}">Groupes</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
|
||||
<div class="col-10">
|
||||
<form method="post" action="/submit" class="row g-2 align-items-center">
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-2">
|
||||
<input
|
||||
type="text"
|
||||
name="query"
|
||||
class="form-control bg-dark text-white"
|
||||
placeholder="Nom de la machine">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-2">
|
||||
<select name="time" class="form-select bg-dark text-white" id="time-select">
|
||||
{% for hour in range(0, 24) %}
|
||||
<option value="{{ '%02d:00'|format(hour) }}">{{ '%02d:00'|format(hour) }}</option>
|
||||
@@ -40,15 +40,24 @@
|
||||
</div>
|
||||
|
||||
<div class="col-auto gap-1 ms-auto">
|
||||
<form method="post" action="/submit-default" class="d-flex gap-1">
|
||||
<span class="text-white">Heure par défaut :</span>
|
||||
<form method="post" action="/submit-default" class="d-flex align-items-center gap-1">
|
||||
<select name="default-time" class="form-select bg-dark text-white flex-grow-1" id="default-time-select">
|
||||
{% for hour in range(0, 24) %}
|
||||
<option value="{{ '%02d:00'|format(hour) }}">{{ '%02d:00'|format(hour) }}</option>
|
||||
<option value="{{ '%02d:30'|format(hour) }}">{{ '%02d:30'|format(hour) }}</option>
|
||||
{% set h1 = '%02d:00'|format(hour) %}
|
||||
{% set h2 = '%02d:30'|format(hour) %}
|
||||
|
||||
<option value="{{ h1 }}"
|
||||
{% if h1 == default_time %}selected{% endif %}>
|
||||
{{ h1 }}
|
||||
</option>
|
||||
|
||||
<option value="{{ h2 }}"
|
||||
{% if h2 == default_time %}selected{% endif %}>
|
||||
{{ h2 }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="submit" class="btn btn-sm btn-primary">
|
||||
<button type="submit" class="btn btn-sm btn-primary w-100">
|
||||
<i class="bi bi-save"> Save</i>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user