This commit is contained in:
Antoine Waehren 2021-12-03 01:11:32 +01:00
commit b929181dc5
3 changed files with 37 additions and 6 deletions

4
app.py
View File

@ -10,6 +10,10 @@ app = Flask(__name__)
def main(): def main():
return pages.main() return pages.main()
@app.route('/sauveteurs/<int:idsauveteur>')
def sauveteur(idsauveteur):
return pages.sauveteur(idsauveteur)
@app.errorhandler(404) @app.errorhandler(404)
def error(e): def error(e):
return pages.error() return pages.error()

View File

@ -1,8 +1,20 @@
### Fonctions communes ### Fonctions communes
import sqlite3
def read(path): def ex_sql(db_name,request,replace=""):
# Retourne le contenu texte d'un fichier conn = sqlite3.connect(db_name)
f = open(path,'r') conn.row_factory=sqlite3.Row # La fonction retourne des dicos et pas des listes
result = f.read() cur = conn.cursor()
f.close() if not replace=="":
return result cur.execute(request,replace)
else:
cur.execute(request)
conn.commit()
a = None
if "SELECT" in request.upper():
a = cur.fetchall()
for i in range(len(a)):
a[i] = dict(a[i]) # Convertir les dicos sqlite3 en dico classiques python
cur.close()
conn.close()
return a

View File

@ -1,6 +1,8 @@
from flask import render_template from flask import render_template
import definitions as lib import definitions as lib
dbname = "site.db"
# Fonctions qui seront associées à des URLs # Fonctions qui seront associées à des URLs
def main(): def main():
@ -8,3 +10,16 @@ def main():
def error(): def error():
return render_template("error.html") return render_template("error.html")
def sauveteur(idsauveteur):
dico = {}
dico["nom"] = "John"
dico["prenom"] = "Doe"
dico["nb_sauvetages"] = 666
dico["nb_sauves"] = 666
dico["gratifications"] = 1
dico["description"] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at odio cursus, rutrum odio non, dignissim risus. Pellentesque non varius ante. Vivamus scelerisque pulvinar mauris, nec imperdiet ante mattis et."
result = lib.ex_sql(dbname,"SELECT * FROM sauveteur WHERE personal_id=?",(idsauveteur,))[0]
dico["nom"] = result["nom"]
dico["prenom"] = result["prenom"]
return render_template("sauveteur.html",**dico)