Black formatting
This commit is contained in:
parent
537e509027
commit
53316c2ce9
7 changed files with 28 additions and 22 deletions
|
@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@background.task
|
@background.task
|
||||||
def submit_new_comment(comment):
|
def submit_new_comment(comment):
|
||||||
site_url = app.config['CONFIG'].get(ConfigParameter.SITE_URL)
|
site_url = app.config["CONFIG"].get(ConfigParameter.SITE_URL)
|
||||||
comment_list = (
|
comment_list = (
|
||||||
f"Web admin interface: {site_url}/web/admin",
|
f"Web admin interface: {site_url}/web/admin",
|
||||||
"",
|
"",
|
||||||
|
@ -34,9 +34,9 @@ def submit_new_comment(comment):
|
||||||
email_body = "\n".join(comment_list)
|
email_body = "\n".join(comment_list)
|
||||||
|
|
||||||
# send email to notify admin
|
# send email to notify admin
|
||||||
site_name = app.config['CONFIG'].get(ConfigParameter.SITE_NAME)
|
site_name = app.config["CONFIG"].get(ConfigParameter.SITE_NAME)
|
||||||
subject = f"STACOSYS {site_name}"
|
subject = f"STACOSYS {site_name}"
|
||||||
if app.config['MAILER'].send(subject, email_body):
|
if app.config["MAILER"].send(subject, email_body):
|
||||||
logger.debug("new comment processed")
|
logger.debug("new comment processed")
|
||||||
# save notification datetime
|
# save notification datetime
|
||||||
dao.notify_comment(comment)
|
dao.notify_comment(comment)
|
||||||
|
|
|
@ -46,7 +46,7 @@ def new_form_comment():
|
||||||
# send notification e-mail asynchronously
|
# send notification e-mail asynchronously
|
||||||
submit_new_comment(comment)
|
submit_new_comment(comment)
|
||||||
|
|
||||||
return redirect(app.config['CONFIG'].get(ConfigParameter.SITE_REDIRECT), code=302)
|
return redirect(app.config["CONFIG"].get(ConfigParameter.SITE_REDIRECT), code=302)
|
||||||
|
|
||||||
|
|
||||||
def check_form_data(posted_comment):
|
def check_form_data(posted_comment):
|
||||||
|
|
|
@ -24,8 +24,8 @@ def index():
|
||||||
def is_login_ok(username, password):
|
def is_login_ok(username, password):
|
||||||
hashed = hashlib.sha256(password.encode()).hexdigest().upper()
|
hashed = hashlib.sha256(password.encode()).hexdigest().upper()
|
||||||
return (
|
return (
|
||||||
app.config['CONFIG'].get(ConfigParameter.WEB_USERNAME) == username
|
app.config["CONFIG"].get(ConfigParameter.WEB_USERNAME) == username
|
||||||
and app.config['CONFIG'].get(ConfigParameter.WEB_PASSWORD) == hashed
|
and app.config["CONFIG"].get(ConfigParameter.WEB_PASSWORD) == hashed
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +41,9 @@ def login():
|
||||||
flash("Identifiant ou mot de passe incorrect")
|
flash("Identifiant ou mot de passe incorrect")
|
||||||
return redirect("/web/login")
|
return redirect("/web/login")
|
||||||
# GET
|
# GET
|
||||||
return render_template("login_" + app.config['CONFIG'].get(ConfigParameter.LANG) + ".html")
|
return render_template(
|
||||||
|
"login_" + app.config["CONFIG"].get(ConfigParameter.LANG) + ".html"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/web/logout", methods=["GET"])
|
@app.route("/web/logout", methods=["GET"])
|
||||||
|
@ -54,7 +56,7 @@ def logout():
|
||||||
def admin_homepage():
|
def admin_homepage():
|
||||||
if not (
|
if not (
|
||||||
"user" in session
|
"user" in session
|
||||||
and session["user"] == app.config['CONFIG'].get(ConfigParameter.WEB_USERNAME)
|
and session["user"] == app.config["CONFIG"].get(ConfigParameter.WEB_USERNAME)
|
||||||
):
|
):
|
||||||
# TODO localization
|
# TODO localization
|
||||||
flash("Vous avez été déconnecté.")
|
flash("Vous avez été déconnecté.")
|
||||||
|
@ -62,9 +64,9 @@ def admin_homepage():
|
||||||
|
|
||||||
comments = dao.find_not_published_comments()
|
comments = dao.find_not_published_comments()
|
||||||
return render_template(
|
return render_template(
|
||||||
"admin_" + app.config['CONFIG'].get(ConfigParameter.LANG) + ".html",
|
"admin_" + app.config["CONFIG"].get(ConfigParameter.LANG) + ".html",
|
||||||
comments=comments,
|
comments=comments,
|
||||||
baseurl=app.config['CONFIG'].get(ConfigParameter.SITE_URL),
|
baseurl=app.config["CONFIG"].get(ConfigParameter.SITE_URL),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +78,7 @@ def admin_action():
|
||||||
flash("Commentaire introuvable")
|
flash("Commentaire introuvable")
|
||||||
elif request.form.get("action") == "APPROVE":
|
elif request.form.get("action") == "APPROVE":
|
||||||
dao.publish_comment(comment)
|
dao.publish_comment(comment)
|
||||||
app.config['RSS'].generate()
|
app.config["RSS"].generate()
|
||||||
# TODO localization
|
# TODO localization
|
||||||
flash("Commentaire publié")
|
flash("Commentaire publié")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -9,14 +9,16 @@ import sys
|
||||||
from stacosys.db import database
|
from stacosys.db import database
|
||||||
from stacosys.interface import api, app, form
|
from stacosys.interface import api, app, form
|
||||||
from stacosys.interface.web import admin
|
from stacosys.interface.web import admin
|
||||||
|
from stacosys.service.configuration import Config, ConfigParameter
|
||||||
from stacosys.service.mail import Mailer
|
from stacosys.service.mail import Mailer
|
||||||
from stacosys.service.rssfeed import Rss
|
from stacosys.service.rssfeed import Rss
|
||||||
from stacosys.service.configuration import Config, ConfigParameter
|
|
||||||
|
|
||||||
|
|
||||||
# configure logging
|
# configure logging
|
||||||
def configure_logging() -> logging.Logger:
|
def configure_logging() -> logging.Logger:
|
||||||
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(name)s %(levelname)s %(message)s")
|
logging.basicConfig(
|
||||||
|
level=logging.INFO, format="[%(asctime)s] %(name)s %(levelname)s %(message)s"
|
||||||
|
)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logging.getLogger("werkzeug").level = logging.WARNING
|
logging.getLogger("werkzeug").level = logging.WARNING
|
||||||
return logger
|
return logger
|
||||||
|
@ -72,9 +74,9 @@ def main(config_pathname):
|
||||||
mailer = configure_and_validate_mailer(config, logger)
|
mailer = configure_and_validate_mailer(config, logger)
|
||||||
|
|
||||||
logger.info("start interfaces %s %s %s", api, form, admin)
|
logger.info("start interfaces %s %s %s", api, form, admin)
|
||||||
app.config['CONFIG'] = config
|
app.config["CONFIG"] = config
|
||||||
app.config['MAILER'] = mailer
|
app.config["MAILER"] = mailer
|
||||||
app.config['RSS'] = rss
|
app.config["RSS"] = rss
|
||||||
app.run(
|
app.run(
|
||||||
host=config.get(ConfigParameter.HTTP_HOST),
|
host=config.get(ConfigParameter.HTTP_HOST),
|
||||||
port=config.get_int(ConfigParameter.HTTP_PORT),
|
port=config.get_int(ConfigParameter.HTTP_PORT),
|
||||||
|
|
|
@ -16,7 +16,9 @@ class Mailer:
|
||||||
self._smtp_password = ""
|
self._smtp_password = ""
|
||||||
self._site_admin_email = ""
|
self._site_admin_email = ""
|
||||||
|
|
||||||
def configure_smtp(self, smtp_host: str, smtp_port: int, smtp_login: str, smtp_password: str) -> None:
|
def configure_smtp(
|
||||||
|
self, smtp_host: str, smtp_port: int, smtp_login: str, smtp_password: str
|
||||||
|
) -> None:
|
||||||
self._smtp_host = smtp_host
|
self._smtp_host = smtp_host
|
||||||
self._smtp_port = smtp_port
|
self._smtp_port = smtp_port
|
||||||
self._smtp_login = smtp_login
|
self._smtp_login = smtp_login
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from stacosys.service.configuration import Config
|
from stacosys.service.configuration import Config, ConfigParameter
|
||||||
from stacosys.service.configuration import ConfigParameter
|
|
||||||
|
|
||||||
EXPECTED_DB = "sqlite://db.sqlite"
|
EXPECTED_DB = "sqlite://db.sqlite"
|
||||||
EXPECTED_HTTP_PORT = 8080
|
EXPECTED_HTTP_PORT = 8080
|
||||||
|
@ -12,6 +11,7 @@ EXPECTED_LANG = "fr"
|
||||||
|
|
||||||
config = Config()
|
config = Config()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def init_config():
|
def init_config():
|
||||||
config.put(ConfigParameter.DB, EXPECTED_DB)
|
config.put(ConfigParameter.DB, EXPECTED_DB)
|
||||||
|
|
|
@ -17,9 +17,9 @@ def client():
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
database.configure("sqlite:memory://db.sqlite")
|
database.configure("sqlite:memory://db.sqlite")
|
||||||
logger.info(f"start interface {form}")
|
logger.info(f"start interface {form}")
|
||||||
app.config['CONFIG'] = Config()
|
app.config["CONFIG"] = Config()
|
||||||
app.config['MAILER'] = Mailer()
|
app.config["MAILER"] = Mailer()
|
||||||
app.config['RSS'] = Rss()
|
app.config["RSS"] = Rss()
|
||||||
return app.test_client()
|
return app.test_client()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue