#! /usr/bin/python # -*- coding:utf-8 -*- from flask import Flask, render_template, request, redirect, url_for app = Flask(__name__) #taches : dictionnaire (tableau associatif) de tâches taches=[] #id : identifiant de la tache id = 1 @app.route('/') def index(): global taches # fournir au template index.html le tableau taches accomplie et non accomplie accomplies = [] nonaccomplies = [] for tache in taches: if tache["accomplie"] == False: nonaccomplies.append(tache) else: accomplies.append(tache) return render_template('index.html', accomplies=accomplies, nonaccomplies=nonaccomplies) @app.route('/ajout', methods=['POST']) def ajout(): # utiliser les variables globales taches et id global taches, id vartache = request.form['tache'] taches.append({"id":id, "libelle":vartache, "accomplie":False}) #incrémenter id pour la prochaine tâche id = id + 1 return redirect(url_for('index')) @app.route('/miseajour', methods=['POST']) def miseajour(): # utiliser les variables globales taches et id global taches, id varid = request.form['choix'] # mise à jour de la tâche for tache in taches: if tache["id"] == int(varid): tache["accomplie"] = True return redirect(url_for('index')) if __name__ == '__main__': app.run(debug=True, port=5005)