-
Notifications
You must be signed in to change notification settings - Fork 0
/
serveur.py
76 lines (61 loc) · 3.01 KB
/
serveur.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# flask --app serveur.py run --debug
from flask import Flask, render_template, url_for, request, g
from markupsafe import escape
import atexit
import time
import sqlite3
app = Flask(__name__)
@app.before_request
def conDataBase():
g.con = sqlite3.connect("todo2.db")
g.cur = g.con.cursor()
@app.after_request
def conClose(response):
g.con.close()
return response
@app.route('/')
def index():
# res = g.cur.execute("SELECT name, description, start, end, reminder FROM `tasks`")
tasks = ''
# tasks = [(1, 'Le nom', 'La grosse description test test test test fezzihe_z iufhfhbzff efz ef zef e fz efzefes ef es efds efesfssd', time.time(), time.time(), 280), (2, 'Le nom', 'La grosse description', time.time(), time.time(), 280), (2, 'Le nom', 'La grosse description', time.time(), time.time(), 280), (2, 'Le nom', 'La grosse description', time.time(), time.time(), 280)]
return render_template('task_list.j2', todoList=tasks, openlist=(1, 'Slay', 'Description, ici pour Slaaaaaay', 'pink'))
@app.route('/api/addEditTask', methods=['POST'])
def addEditTask():
id = None if empty(request.form.get('id')) else request.form.get('id')
name = None if empty(request.form.get('title')) else request.form.get('title')
description = None if empty(request.form.get('description')) else request.form.get('description')
start = None if empty(request.form.get('dateStart')) else request.form.get('dateStart')
end = None if empty(request.form.get('dateEnd')) else request.form.get('dateEnd')
reminder = None if empty(request.form.get('reminder')) else request.form.get('reminder')
if id == None :
# Ajouter la tâche à la base de données en utilisant les données récupérées
g.cur.execute("INSERT INTO tasks (name, description, start, end, reminder) VALUES (?, ?, ?, ?, ?)", (name, description, start, end, reminder))
g.con.commit()
return {'status': '1', 'message': 'Task added successfully'}
else:
g.cur.execute("UPDATE tasks SET name=?, description=?, start=?, end=?, reminder=? WHERE id=?", (name, description, start, end, reminder, id))
g.con.commit()
return {'status': '1', 'message': 'Task edited successfully'} # Yes verry French
@app.route('/api/getAllTask', methods=['POST'])
def getAllTask():
res = g.cur.execute("SELECT id, name, description, start, end, reminder, donne FROM `tasks`")
tasks = res.fetchall()
return tasks
@app.route('/api/taskChageState', methods=['POST'])
def taskChageState():
state = request.form.get('state')
id = None if empty(request.form.get('id')) else request.form.get('id')
g.cur.execute("UPDATE tasks SET donne=? WHERE id=?", (state, id))
g.con.commit()
return {'status': '1', 'message': 'state changed successfully'} # Yes verry French
def empty(variable):
# Tester les vide car python c'est de la m et il y a pas de empty()
if variable is None:
return True
if variable == 'null':
return True
if variable == '0':
return True
if variable == 'NaN':
return True
return False