Merge branch 'master' of https://forge.chapril.org/CretinsMotorisesIngenieux/Marin
This commit is contained in:
commit
98098871c9
3
app.py
3
app.py
@ -13,8 +13,7 @@ def main():
|
||||
@app.route('/search', methods=['GET', 'POST'])
|
||||
def search():
|
||||
texte = request.form["search"]
|
||||
print(texte)
|
||||
return pages.main()
|
||||
return pages.search(texte)
|
||||
|
||||
@app.route('/sauveteurs/<int:idsauveteur>')
|
||||
@app.route('/sauveteur/<int:idsauveteur>')
|
||||
|
28
pages.py
28
pages.py
@ -1,5 +1,6 @@
|
||||
from flask import render_template
|
||||
import definitions as lib
|
||||
from difflib import SequenceMatcher
|
||||
|
||||
dbname = "site.db"
|
||||
|
||||
@ -48,3 +49,30 @@ def sauveteur(idsauveteur):
|
||||
return render_template("sauveteur.html",**dico)
|
||||
else:
|
||||
return error()
|
||||
|
||||
def search(texte):
|
||||
sauveurs = lib.ex_sql(dbname,"SELECT * FROM sauveteur")
|
||||
bateaux = lib.ex_sql(dbname,"SELECT * FROM bateau")
|
||||
totals = sauveurs+bateaux
|
||||
for i in totals:
|
||||
i["score"] = 0
|
||||
for key in i.keys():
|
||||
if key!="score":
|
||||
r = 1
|
||||
if key=="nom":
|
||||
r = 3
|
||||
i["score"] += SequenceMatcher(None, texte, str(i[key])).ratio()*r
|
||||
totals.sort(key=lambda x : x["score"])
|
||||
totals.reverse()
|
||||
totals = totals[:8]
|
||||
results = []
|
||||
for i in totals:
|
||||
r = {}
|
||||
if "ship_id" in i.keys():
|
||||
r["lien"] = "/bateaux/"+str(i["ship_id"])
|
||||
elif "personal_id" in i.keys():
|
||||
r["lien"] = "/sauveteurs/"+str(i["personal_id"])
|
||||
r["nom"] = i["nom"]
|
||||
|
||||
results.append(r)
|
||||
return render_template("searchresults.html",liste=results)
|
||||
|
9
templates/searchresults.html
Normal file
9
templates/searchresults.html
Normal file
@ -0,0 +1,9 @@
|
||||
<ul>
|
||||
|
||||
{% for result in liste %}
|
||||
|
||||
<li><a href="{{result.lien}}">{{result.nom}}</a></li>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user