From: Joe Rickerby Date: Wed, 10 Jan 2018 14:59:42 +0000 (+0000) Subject: New default styling for messages sent via the web interface X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=3ea85ddad23e6cc7c0d7fe466f98c94ecb49090d;p=sirius.git New default styling for messages sent via the web interface --- diff --git a/sirius/coding/default_template.html b/sirius/coding/default_template.html new file mode 100644 index 0000000..855ea23 --- /dev/null +++ b/sirius/coding/default_template.html @@ -0,0 +1,48 @@ + + + + + +
+ {{ date.strftime('%H:%M | %d-%b-%Y') }}{% if from_name %} | {{ from_name }}{% endif %} +
+ {{ raw_html|safe }} + + diff --git a/sirius/coding/templating.py b/sirius/coding/templating.py index 565e303..188ad4d 100644 --- a/sirius/coding/templating.py +++ b/sirius/coding/templating.py @@ -1,20 +1,20 @@ +import os, datetime import jinja2 -DEFAULT_TEMPLATE = '''\ - - - {{ raw_html|safe }} - - -''' +DEFAULT_TEMPLATE_FILE = os.path.join(os.path.dirname(__file__), 'default_template.html') ENV = jinja2.Environment() - - # TODO apply scrubber library if wanted. # https://pypi.python.org/pypi/scrubber -def default_template(raw_html): - t = ENV.from_string(DEFAULT_TEMPLATE) - return t.render(raw_html=raw_html) +def default_template(raw_html, from_name): + with open(DEFAULT_TEMPLATE_FILE) as f: + template = f.read() + + t = ENV.from_string(template) + return t.render( + raw_html=raw_html, + date=datetime.datetime.now(), + from_name=from_name + ) diff --git a/sirius/web/external_api.py b/sirius/web/external_api.py index ae7cfbd..817cd03 100644 --- a/sirius/web/external_api.py +++ b/sirius/web/external_api.py @@ -45,7 +45,11 @@ def print_html(printer_id): flask.abort(500) pixels = image_encoding.default_pipeline( - templating.default_template(task['message'])) + templating.default_template( + task['message'], + from_name=login.current_user.username + ) + ) hardware_message = None if task['face'] == "noface": diff --git a/sirius/web/printer_print.py b/sirius/web/printer_print.py index 0916b35..a768cad 100644 --- a/sirius/web/printer_print.py +++ b/sirius/web/printer_print.py @@ -76,7 +76,7 @@ def printer_print(printer_id): # TODO: move image encoding into a pthread. # TODO: use templating to avoid injection attacks pixels = image_encoding.default_pipeline( - templating.default_template(form.message.data)) + templating.default_template(form.message.data, from_name=login.current_user.username)) hardware_message = None if form.face.data == "noface": @@ -139,7 +139,7 @@ def preview(user_id, username, printer_id): message = flask.request.data pixels = image_encoding.default_pipeline( - templating.default_template(message)) + templating.default_template(message, from_name=login.current_user.username)) png = io.BytesIO() pixels.save(png, "PNG")