2020-09-27 10:17:06 +00:00
|
|
|
from flask import Flask, render_template, request, redirect, url_for, make_response
|
2020-09-26 23:32:38 +00:00
|
|
|
from os import path
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
app = Flask('ui', static_url_path="/static")
|
|
|
|
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def slash():
|
2020-09-27 10:17:06 +00:00
|
|
|
response = make_response(render_template("index.html"))
|
|
|
|
response.headers["Content-Security-Policy"] = "default-src 'self'"
|
|
|
|
return response
|
2020-09-26 23:32:38 +00:00
|
|
|
|
|
|
|
@app.route("/ajout")
|
|
|
|
def ajout():
|
|
|
|
return render_template("ajout.html")
|
|
|
|
|
|
|
|
@app.route("/apropos")
|
|
|
|
def apropos():
|
|
|
|
return render_template("apropos.html")
|
|
|
|
|
|
|
|
@app.route("/bizutage", methods=["POST"])
|
|
|
|
def bizutage():
|
|
|
|
if request.method == "POST":
|
|
|
|
titre = request.values['titre']
|
|
|
|
lien = request.values['lien']
|
|
|
|
desc = request.values['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")
|
2020-09-27 10:17:06 +00:00
|
|
|
|
2020-09-27 10:44:59 +00:00
|
|
|
if nouvLienHtml.find("script") != None:
|
|
|
|
erreur = "Vous ne pouvez pas charger de balises script !"
|
|
|
|
return render_template("ajout.html", erreur=erreur)
|
|
|
|
|
2020-09-26 23:32:38 +00:00
|
|
|
with open("templates/index.html", 'r') as file:
|
|
|
|
soup = BeautifulSoup(file, 'html.parser')
|
2020-09-27 10:17:06 +00:00
|
|
|
soup.find("hr").insert_after("", nouvLienHtml)
|
2020-09-26 23:32:38 +00:00
|
|
|
with open("templates/index.html", 'w') as file:
|
|
|
|
file.write(soup.prettify())
|
|
|
|
|
|
|
|
with open("lite/index.html", 'r') as file:
|
|
|
|
soup = BeautifulSoup(file, 'html.parser')
|
2020-09-27 10:17:06 +00:00
|
|
|
soup.find("hr").insert_after("", nouvLienHtml)
|
2020-09-26 23:32:38 +00:00
|
|
|
with open("lite/index.html", 'w') as file:
|
|
|
|
file.write(soup.prettify())
|
2020-09-27 10:44:59 +00:00
|
|
|
|
|
|
|
reussite = "Lien ajouté !"
|
2020-09-26 23:32:38 +00:00
|
|
|
else:
|
|
|
|
print("error")
|
2020-09-27 10:44:59 +00:00
|
|
|
return render_template("ajout.html", reussi=reussite)
|
2020-09-26 23:32:38 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run()
|