From 1b32206a23ecdbdc3bbaf2cd15ce2153a3d9cb68 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Wed, 28 Sep 2022 00:39:44 +0000 Subject: [PATCH] Implement template-switching. Point testing subdomain to port 1111. Fix busted
--- Caddyfile | 8 ++++++-- undercover/routes.py | 22 +++++++++++++++++----- undercover/templates/base.jinja2 | 3 ++- undercover/templates/writing.jinja2 | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Caddyfile b/Caddyfile index 91d59ba..13d3d2f 100644 --- a/Caddyfile +++ b/Caddyfile @@ -1,3 +1,7 @@ -undercover.cafe +testing.undercover.cafe { + reverse_proxy :1111 +} -reverse_proxy :8080 +undercover.cafe { + reverse_proxy :8080 +} diff --git a/undercover/routes.py b/undercover/routes.py index f90eb89..624df0d 100644 --- a/undercover/routes.py +++ b/undercover/routes.py @@ -63,9 +63,9 @@ class CLForm(Form): "My name is {\\username}. I'm excited for the opportunity to work as " "{\\jobAndPronoun} with your company. I think my {\\skillTypes} knowledge " "of {\\mySkills} could contribute well to your team.\n\n" - + "I am passionate about what I do, and I think we would work well together.\n\n" - + "Thank you for your consideration." ) ) @@ -116,11 +116,22 @@ def index_get(): if len(letters) > 0: letter_names = [(i + 1, letter.title) for i, letter in enumerate(letters)] form.letterName.choices = letter_names - # TODO: Load this data more dynamically - # I.e. use a dictionary instead of explicitly-defined fields - data = json.loads(letters[0].contents) form.letterName.data = 1 + selected_letter = request.args.get('letter_name') + if selected_letter: + for i, letter in enumerate(letters): + if letter.title == selected_letter: + form.letterName.data = i + 1 + break + + # TODO: Load this data more dynamically + # I.e. use a dictionary instead of explicitly-defined fields + data = json.loads(letters[form.letterName.data - 1].contents) + + # Ensures default value is set + form.letterName.process_data(form.letterName.data) + form.company.data = data['company'] form.body.data = data['body'] form.closingText.data = data['closingText'] @@ -254,3 +265,4 @@ def generate_pdf(): return resp return render_index(form=form) + diff --git a/undercover/templates/base.jinja2 b/undercover/templates/base.jinja2 index 20543dc..89bee77 100644 --- a/undercover/templates/base.jinja2 +++ b/undercover/templates/base.jinja2 @@ -19,10 +19,11 @@ {{ error }}
{% endif %} -
{% block content %} {{ content }} {% endblock content %} +
diff --git a/undercover/templates/writing.jinja2 b/undercover/templates/writing.jinja2 index 9841878..9ad8ef1 100644 --- a/undercover/templates/writing.jinja2 +++ b/undercover/templates/writing.jinja2 @@ -62,7 +62,7 @@
{% if username %} - {{ render_field(form.letterName) }} + {{ render_field(form.letterName, onchange="window.location = '/?letter_name=' + this.options[this.value - 1].label") }} {% endif %} {{ render_field(form.username) }} {{ render_field(form.company) }}