From 9b2c14e3a0476bf2cb1125d706e868cb978036a0 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Sun, 30 Jan 2022 18:56:52 +0100 Subject: [PATCH] draft web admin: no action, no security --- run.py | 18 +++---- stacosys/db/dao.py | 4 ++ stacosys/interface/__init__.py | 3 ++ stacosys/interface/templates/admin_fr.html | 61 ++++++++++++++++++++++ stacosys/interface/web/admin.py | 24 +++++++++ stacosys/interface/webadmin.py | 28 ---------- 6 files changed, 101 insertions(+), 37 deletions(-) create mode 100644 stacosys/interface/templates/admin_fr.html create mode 100644 stacosys/interface/web/admin.py delete mode 100644 stacosys/interface/webadmin.py diff --git a/run.py b/run.py index 520e9ac..3608da2 100644 --- a/run.py +++ b/run.py @@ -1,21 +1,21 @@ #!/usr/bin/python # -*- coding: UTF-8 -*- -import sys -import os import argparse -import logging import hashlib +import logging +import os +import sys from stacosys.conf.config import Config, ConfigParameter -from stacosys.db import database -from stacosys.core.rss import Rss from stacosys.core.mailer import Mailer -from stacosys.interface import app +from stacosys.core.rss import Rss +from stacosys.db import database from stacosys.interface import api +from stacosys.interface import app from stacosys.interface import form -from stacosys.interface import webadmin from stacosys.interface import scheduler +from stacosys.interface.web import admin # configure logging @@ -33,7 +33,6 @@ def configure_logging(level): def stacosys_server(config_pathname): - # configure logging logger = logging.getLogger(__name__) configure_logging(logging.INFO) @@ -107,7 +106,8 @@ def stacosys_server(config_pathname): # inject config parameters into flask app.config.update(SITE_REDIRECT=conf.get(ConfigParameter.SITE_REDIRECT)) - logger.info(f"start interfaces {api} {form} {webadmin}") + app.config.update(SITE_URL=conf.get(ConfigParameter.SITE_URL)) + logger.info(f"start interfaces {api} {form} {admin}") # start Flask app.run( diff --git a/stacosys/db/dao.py b/stacosys/db/dao.py index 0a14761..e24fec2 100644 --- a/stacosys/db/dao.py +++ b/stacosys/db/dao.py @@ -29,6 +29,10 @@ def find_not_notified_comments(): return Comment.select().where(Comment.notified.is_null()) +def find_not_published_comments(): + return Comment.select().where(Comment.published.is_null()) + + def find_published_comments_by_url(url): return Comment.select(Comment).where((Comment.url == url) & (Comment.published.is_null(False))).order_by( +Comment.published) diff --git a/stacosys/interface/__init__.py b/stacosys/interface/__init__.py index 1fab892..ee1c258 100644 --- a/stacosys/interface/__init__.py +++ b/stacosys/interface/__init__.py @@ -4,3 +4,6 @@ from flask import Flask app = Flask(__name__) + +# Set the secret key to some random bytes. Keep this really secret! +app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' \ No newline at end of file diff --git a/stacosys/interface/templates/admin_fr.html b/stacosys/interface/templates/admin_fr.html new file mode 100644 index 0000000..ee77e35 --- /dev/null +++ b/stacosys/interface/templates/admin_fr.html @@ -0,0 +1,61 @@ + + + + + +Stacosys + + + +
+

Modération des commentaires

+
+
+ {% with messages = get_flashed_messages() %} + {% if messages %} +
+ {% for message in messages %} +

{{ message }}

+ {% endfor %} +
+ {% endif %} + {% endwith %} + + + + + + + + + + + + {% for comment in comments %} + + + + + + + + {% endfor %} + +
DateAuteurCommentaireArticleActions
{{ comment.created }}{{ comment.author_name }}{{ comment.content }}{{ comment.url }} +
+ + + +
+
+ + + +
+
+
+ + + \ No newline at end of file diff --git a/stacosys/interface/web/admin.py b/stacosys/interface/web/admin.py new file mode 100644 index 0000000..29f97f2 --- /dev/null +++ b/stacosys/interface/web/admin.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import logging + +from flask import request, redirect, flash, render_template + +from stacosys.db import dao +from stacosys.interface import app + +logger = logging.getLogger(__name__) + + +@app.route("/web", methods=["GET"]) +def admin_homepage(): + lang = "fr" + comments = dao.find_not_published_comments() + return render_template("admin_" + lang + ".html", comments=comments, baseurl=app.config.get("SITE_URL")) + + +@app.route("/web", methods=["POST"]) +def admin_action(): + flash(request.form.get("comment") + " " + request.form.get("action")) + return redirect('/web') diff --git a/stacosys/interface/webadmin.py b/stacosys/interface/webadmin.py deleted file mode 100644 index 5f0ca50..0000000 --- a/stacosys/interface/webadmin.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import logging -import os -from stacosys.core.templater import Templater, Template - -from flask import jsonify, request -from flask import render_template - -from stacosys.db import dao -from stacosys.interface import app - -logger = logging.getLogger(__name__) - - -current_path = os.path.dirname(__file__) -template_path = os.path.abspath(os.path.join(current_path, "../templates")) -templater = Templater(template_path) - -@app.route("/web/comment", methods=["GET"]) -def web_comment_approval(): - lang = "fr" - return templater.get_template(lang, Template.WEB_COMMENT_APPROVAL).render( - name="Yax") - - -