--- /dev/null
+<html>
+ <head>
+ <style>
+ html, body {
+ margin: 0;
+ padding: 0;
+ background-color: white;
+ }
+
+ body {
+ /*
+ first line must be white because of a bug in the image encoder,
+ that inverts the image if the first pixel is black
+ */
+ margin-top: 1px;
+ margin-bottom: 80px;
+ border: 1px;
+ font-family: Helvetica, Arial, sans-serif;
+ font-size: 30px;
+ }
+ h1, h2, h3, h4, h5, h6 {
+ margin-bottom: 20px;
+ }
+
+ li {
+ margin-bottom: 0.5em;
+ }
+
+ .header {
+ font-weight: 800;
+ text-transform: uppercase;
+ font-size: 18px;
+ margin-bottom: 18px;
+ text-align: center;
+ }
+
+ img {
+ max-width: 100%;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="header">
+ {{ date.strftime('%H:%M | %d-%b-%Y') }}{% if from_name %} | {{ from_name }}{% endif %}
+ </div>
+ {{ raw_html|safe }}
+ </body>
+</html>
+import os, datetime
import jinja2
-DEFAULT_TEMPLATE = '''\
-<html>
- <body>
- {{ raw_html|safe }}
- </body>
-</html>
-'''
+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
+ )
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":
# 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":
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")