Compare commits
2 Commits
0c3fe53ef2
...
a3071393d9
Author | SHA1 | Date | |
---|---|---|---|
a3071393d9 | |||
1a8bbd536b |
3
app.py
3
app.py
@ -13,8 +13,7 @@ def main():
|
|||||||
@app.route('/search', methods=['GET', 'POST'])
|
@app.route('/search', methods=['GET', 'POST'])
|
||||||
def search():
|
def search():
|
||||||
texte = request.form["search"]
|
texte = request.form["search"]
|
||||||
print(texte)
|
return pages.search(texte)
|
||||||
return pages.main()
|
|
||||||
|
|
||||||
@app.route('/sauveteurs/<int:idsauveteur>')
|
@app.route('/sauveteurs/<int:idsauveteur>')
|
||||||
@app.route('/sauveteur/<int:idsauveteur>')
|
@app.route('/sauveteur/<int:idsauveteur>')
|
||||||
|
28
pages.py
28
pages.py
@ -1,5 +1,6 @@
|
|||||||
from flask import render_template
|
from flask import render_template
|
||||||
import definitions as lib
|
import definitions as lib
|
||||||
|
from difflib import SequenceMatcher
|
||||||
|
|
||||||
dbname = "site.db"
|
dbname = "site.db"
|
||||||
|
|
||||||
@ -48,3 +49,30 @@ def sauveteur(idsauveteur):
|
|||||||
return render_template("sauveteur.html",**dico)
|
return render_template("sauveteur.html",**dico)
|
||||||
else:
|
else:
|
||||||
return error()
|
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