From 3c7b14685e9c196416e4ddd6b772d7558f37e2c2 Mon Sep 17 00:00:00 2001 From: Rick Date: Thu, 1 Oct 2020 00:55:37 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20cat=C3=A9gories?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 27 ++++++++++++-------- static/autres.html | 54 ++++++++++++++++++++++++++++++++++++++++ static/index.html | 9 +++++++ static/informatique.html | 54 ++++++++++++++++++++++++++++++++++++++++ static/musique.html | 54 ++++++++++++++++++++++++++++++++++++++++ static/styles/base.css | 2 +- static/styles/index.css | 31 ++++++++++++++++++++++- 7 files changed, 219 insertions(+), 12 deletions(-) create mode 100644 static/autres.html create mode 100644 static/informatique.html create mode 100644 static/musique.html diff --git a/app.py b/app.py index 032b9af..1030dd9 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ from flask import Flask, render_template, request, redirect, make_response, \ - Markup + Markup from enum import Enum from bs4 import BeautifulSoup import re @@ -17,9 +17,10 @@ class Status(Enum): class Manip(): def ecritureFichierHtml(nouvLien, cheminFichier): + nouvLienHtml = BeautifulSoup(nouvLien, "html.parser") with open(cheminFichier, 'r+') as file: soup = BeautifulSoup(file, 'html.parser') - soup.find("hr").insert_after("", nouvLien) + soup.find("hr").insert_after("", nouvLienHtml) file.seek(0) file.write(soup.prettify()) @@ -42,6 +43,10 @@ def slash(): response.headers["Content-Security-Policy"] = "default-src 'self'" return response +@app.route("/categories/") +def categories(subpath): + return app.send_static_file(subpath + ".html") + @app.route("/ajout") def ajout(): return render_template("ajout.html") @@ -56,25 +61,27 @@ def bizutage_redirect(): @app.route("/bizutage", methods=["POST"]) def bizutage(): - lien = request.values['lien'] - if not valideUrl(lien): + lien = request.values["lien"] + if not Manip.valideUrl(lien): return render_template( "ajout.html", erreur=Status.ERREUR_LIEN.value ) - titre = Markup.escape(request.values['titre']) - desc = Markup.escape(request.values['desc']) - nouvLien = f"""
+ titre = Markup.escape(request.values["titre"]) + desc = Markup.escape(request.values["desc"]) + categorie = Markup.escape(request.values["categories"]) + nouvLien = f"""

{titre}

Lien


{desc}

""" - nouvLienHtml = BeautifulSoup(nouvLien, "html.parser") - ecritureFichierHtml(nouvLienHtml, "static/index.html") - ecritureFichierHtml(nouvLienHtml, "lite/index.html") + Manip.ecritureFichierHtml(nouvLien, "static/index.html") + Manip.ecritureFichierHtml(nouvLien, "static/" + categorie + ".html") + Manip.ecritureFichierHtml(nouvLien, "lite/index.html") + Manip.ecritureFichierHtml(nouvLien, "lite/" + categorie + ".html") return render_template("ajout.html", reussi=Status.BON.value) if __name__ == "__main__": diff --git a/static/autres.html b/static/autres.html new file mode 100644 index 0000000..debd60f --- /dev/null +++ b/static/autres.html @@ -0,0 +1,54 @@ + + + + + + + + Autre + + + + + +
+ + diff --git a/static/index.html b/static/index.html index 0af7871..d8dfc09 100644 --- a/static/index.html +++ b/static/index.html @@ -10,10 +10,19 @@ +

Rafraichissez la page pour voir les derniers liens ajoutés.


diff --git a/static/informatique.html b/static/informatique.html new file mode 100644 index 0000000..ea35b1d --- /dev/null +++ b/static/informatique.html @@ -0,0 +1,54 @@ + + + + + + + + Informatique + + + + + +
+ + diff --git a/static/musique.html b/static/musique.html new file mode 100644 index 0000000..8ac178e --- /dev/null +++ b/static/musique.html @@ -0,0 +1,54 @@ + + + + + + + + Musique + + + + + +
+ + diff --git a/static/styles/base.css b/static/styles/base.css index 95bdf84..c87634c 100644 --- a/static/styles/base.css +++ b/static/styles/base.css @@ -45,4 +45,4 @@ header a:hover { #lienAccueil { text-decoration: none; color: white; -} \ No newline at end of file +} diff --git a/static/styles/index.css b/static/styles/index.css index bd5299f..beaf109 100644 --- a/static/styles/index.css +++ b/static/styles/index.css @@ -1,7 +1,24 @@ +#categories { + height: 3em; +} + #categories ul { list-style-type: none; display: flex; justify-content:space-around; + height: 100%; +} + +#categories li { + padding-top: 1em; +} + +#categories a { + color: white; + text-decoration: none; + padding: 2em; + padding-top: 1em; + padding-bottom: 1em; } .elem { @@ -28,4 +45,16 @@ margin-right: 5px; padding: 5px; background-color: dimgray; -} \ No newline at end of file +} + +.informatique { + background-color: #3A506B; +} + +.musique { + background-color: #A4036F; +} + +.autres { + background-color: #388659; +}