Ajout de la recherche dans la page index.html

This commit is contained in:
Rick 2020-10-21 09:55:15 +02:00
parent 3be39cf23d
commit c5736935b2
Signed by: Rick
GPG Key ID: 9570A7DB7CB2F436
3 changed files with 16 additions and 70 deletions

20
app.py
View File

@ -18,13 +18,20 @@ listeCategorie = ["autres", "informatique", "musique"]
manip = Manip(fichierJson)
#generateurHml = GenerationHtml(fichierJson, listeCategorie)
@app.route('/')
def slash():
def renderIndex(recherche=False):
with open(fichierJson, 'r') as fichier:
liens = json.load(fichier)
listeLiens = liens["liens"]
listeLiens.reverse()
response = make_response(render_template("index.html", listeLiens=listeLiens))
response = make_response(render_template(
"index.html",
listeLiens=listeLiens,
recherche=recherche))
return response
@app.route('/')
def slash():
response = renderIndex()
response.headers["Content-Security-Policy"] = "default-src 'self'"
return response
@ -46,12 +53,7 @@ def ajout():
@app.route("/recherche")
def recherche():
with open(fichierJson, 'r') as fichier:
liens = json.load(fichier)
listeLiens = liens["liens"]
listeLiens.reverse()
response = make_response(render_template("recherche.html", listeLiens=listeLiens))
return response
return renderIndex(True)
@app.route("/apropos")
def apropos():

View File

@ -15,6 +15,7 @@
<a href="/apropos">A propos</a>
</header>
</div>
{% if not recherche %}
<div id="categories">
<ul>
<li><a href="/">Toutes catégories</a></li>
@ -23,6 +24,7 @@
<li class="autres"><a href="/categories/autres">Autres</a></li>
</ul>
</div>
{% endif %}
<p>Rafraichissez la page pour voir les derniers liens ajoutés.</p>
<hr>
{% for lien in listeLiens %}
@ -43,5 +45,8 @@
<hr>
Version Alpha
</footer>
{% if recherche %}
<script src="/static/recherche.js"></script>
{% endif %}
</body>
</html>

View File

@ -1,61 +0,0 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="/static/styles/index.css">
<link rel="stylesheet" href="/static/styles/base.css">
<title>Partage de liens</title>
</head>
<body>
<div id="menu">
<h1>Liens</h1>
<header>
<a href="/recherche">Recherche</a>
<a href="/ajout">Ajout</a>
<a href="/apropos">A propos</a>
</header>
</div>
<div id="categories">
<ul>
<!-- <li><a href="/">Toutes catégories</a></li>
<li class="informatique"><a href="/categories/informatique">Informatique</a></li>
<li class="musique"><a href="/categories/musique">Musique</a></li>
<li class="autres"><a href="/categories/autres">Autres</a></li> -->
</ul>
</div>
<div>
<p>Recherche</p>
<form>
<select id="categorie" name="categorie">
<option value="informatique">Informatique</option>
<option value="musique">Musique</option>
<option value="autres">Autre</option>
<option value="tout" selected>Pas de filtre</option>
</select>
<input type="button" value="Recherche" onClick="recherche()">
</form>
</div>
<hr>
{% for lien in listeLiens %}
<div class="elem {{lien.categorie}}">
<h2>{{lien.titre}}</h2>
<p><a href="{{lien.url}}">{{lien.url}}</a></p>
<hr>
<p>{{lien.desc}}</p>
<p>Tags:</p>
<ul class="tags">
{% for tag in lien.tags %}
<li>{{tag}}</li>
{% endfor %}
</ul>
</div>
{% endfor %}
<footer>
<hr>
Version Alpha
</footer>
<script src="/static/recherche.js"></script>
</body>
</html>