Ajout messages de status lors de l’ajout

This commit is contained in:
Rick 2020-09-27 12:44:59 +02:00
parent 0b8aa84ddb
commit b5d6fed34a
Signed by: Rick
GPG key ID: 9570A7DB7CB2F436
3 changed files with 19 additions and 1 deletions

8
app.py
View file

@ -28,6 +28,10 @@ def bizutage():
nouvLien = "<div class=\"elem\"><h2>{}</h2><p><a href=\"{}\">Lien</a></p><hr><p>{}</p>".format(titre, lien, desc) nouvLien = "<div class=\"elem\"><h2>{}</h2><p><a href=\"{}\">Lien</a></p><hr><p>{}</p>".format(titre, lien, desc)
nouvLienHtml = BeautifulSoup(nouvLien, "html.parser") nouvLienHtml = BeautifulSoup(nouvLien, "html.parser")
if nouvLienHtml.find("script") != None:
erreur = "Vous ne pouvez pas charger de balises script !"
return render_template("ajout.html", erreur=erreur)
with open("templates/index.html", 'r') as file: with open("templates/index.html", 'r') as file:
soup = BeautifulSoup(file, 'html.parser') soup = BeautifulSoup(file, 'html.parser')
soup.find("hr").insert_after("", nouvLienHtml) soup.find("hr").insert_after("", nouvLienHtml)
@ -39,9 +43,11 @@ def bizutage():
soup.find("hr").insert_after("", nouvLienHtml) soup.find("hr").insert_after("", nouvLienHtml)
with open("lite/index.html", 'w') as file: with open("lite/index.html", 'w') as file:
file.write(soup.prettify()) file.write(soup.prettify())
reussite = "Lien ajouté !"
else: else:
print("error") print("error")
return redirect(url_for("ajout")) return render_template("ajout.html", reussi=reussite)
if __name__ == "__main__": if __name__ == "__main__":
app.run() app.run()

7
static/styles/ajout.css Normal file
View file

@ -0,0 +1,7 @@
#erreur {
color: red;
}
#reussi {
color: green;
}

View file

@ -23,5 +23,10 @@
<input type="submit" value="Envoyer"> <input type="submit" value="Envoyer">
</form> </form>
{% if erreur %}
<p id="erreur">{{ erreur }}</p>
{% elif reussi %}
<p id="reussi">{{ reussi }}</p>
{% endif %}
</body> </body>
</html> </html>