From 195f0bb5d8fa87771c4ea3208fc79d642f52fdca Mon Sep 17 00:00:00 2001 From: Ben Spoon Date: Tue, 2 Aug 2016 14:57:38 -0700 Subject: [PATCH] emails: add email template viewer --- emails/email-template-viewer.html | 17 ++++++ tools/email-viewer/emails.py | 87 +++++++++++++++++++++++++++++ tools/email-viewer/requirements.txt | 6 ++ 3 files changed, 110 insertions(+) create mode 100644 emails/email-template-viewer.html create mode 100644 tools/email-viewer/emails.py create mode 100644 tools/email-viewer/requirements.txt diff --git a/emails/email-template-viewer.html b/emails/email-template-viewer.html new file mode 100644 index 000000000..f3f6f9a38 --- /dev/null +++ b/emails/email-template-viewer.html @@ -0,0 +1,17 @@ + + + + Email Template Viewer + + +

Email Template Viewer

+ Here is a list of the templates available: + + + \ No newline at end of file diff --git a/tools/email-viewer/emails.py b/tools/email-viewer/emails.py new file mode 100644 index 000000000..9af305dcc --- /dev/null +++ b/tools/email-viewer/emails.py @@ -0,0 +1,87 @@ +from flask import Flask, render_template +import datetime +import os + +tmpl_dir = '../../emails' + +app = Flask(__name__, template_folder=tmpl_dir) + +@app.template_filter() +def user_reference_filter(value): + return value + +@app.template_filter() +def admin_reference(value): + return value + +@app.template_filter() +def repository_reference(value): + return value + +@app.template_filter() +def team_reference(value): + return value + +app.jinja_env.filters['user_reference'] = user_reference_filter +app.jinja_env.filters['admin_reference'] = admin_reference +app.jinja_env.filters['repository_reference'] = repository_reference +app.jinja_env.filters['team_reference'] = team_reference + + +def app_link_handler(url=None, title=None): + """ Just because it is in the original email tempaltes """ + return 'http://example.com/example' + +def render_with_options(template=None): + """ Pass a bunch of common variables when rendering templates """ + return render_template(template, username="exampleuser", user_reference="testing", + app_logo="https://quay.io/static/img/quay-horizontal-color.svg", token="sdf8SdfKGRME9dse_dfdf", + app_link=app_link_handler, namespace="booboo", repository="foobar", organization="buynlarge", + admin_usernames=["lazercat", "booboocoreos"], teamname="creators", inviter="devtable") + +def get_templates(): + """ Return a list of the available templates """ + return [t.replace('.html', '') for t in os.listdir('../../emails')] + +@app.route("/") +def template_test(): + return render_template('email-template-viewer.html', templates=get_templates()) + +@app.route("/changeemail") +def changeemail(): + return render_with_options('changeemail.html'); + +@app.route("/confirmemail") +def confirmemail(): + return render_with_options('confirmemail.html'); + +@app.route("/emailchanged") +def emailchanged(): + return render_with_options('emailchanged.html'); + +@app.route("/orgrecovery") +def orgrecovery(): + return render_with_options('orgrecovery.html'); + +@app.route("/passwordchanged") +def passwordchanged(): + return render_with_options('passwordchanged.html'); + +@app.route("/paymentfailure") +def paymentfailure(): + return render_with_options('paymentfailure.html'); + +@app.route("/recovery") +def recovery(): + return render_with_options('recovery.html'); + +@app.route("/repoauthorizeemail") +def repoauthorizeemail(): + return render_with_options('repoauthorizeemail.html'); + +@app.route("/teaminvite") +def teaminvite(): + return render_with_options('teaminvite.html'); + +if __name__ == '__main__': + app.run(debug=True) diff --git a/tools/email-viewer/requirements.txt b/tools/email-viewer/requirements.txt new file mode 100644 index 000000000..145e30200 --- /dev/null +++ b/tools/email-viewer/requirements.txt @@ -0,0 +1,6 @@ +Flask==0.10.1 +Jinja2==2.7.2 +MarkupSafe==0.18 +Werkzeug==0.9.4 +itsdangerous==0.23 +wsgiref==0.1.2