From a5704c8c120b523069d591740e22c9c3a7516cb9 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Thu, 29 Sep 2022 07:57:13 -0400 Subject: [PATCH] Start sketching out add-letter button. --- undercover/routes.py | 10 ++++++++++ undercover/templates/writing.jinja2 | 1 + 2 files changed, 11 insertions(+) diff --git a/undercover/routes.py b/undercover/routes.py index 79ca386..af6d355 100644 --- a/undercover/routes.py +++ b/undercover/routes.py @@ -125,6 +125,16 @@ def logout() -> Response: return redirect('/') +@writing_blueprint.route('/add_letter') +def add_letter(user: db.User) -> Response: + # TODO: Add new letter to db + existing_letter_count = len(db.get_user_letters(user.id)) + new_letter_name = f'Letter{existing_letter_count + 2}' + default_form_json = jsonify(CLForm().to_cl_data()).get_data(True) + db.add_letter(user.id, new_letter_name, default_form_json) + return redirect(f'/?letter_name={new_letter_name}') + + @writing_blueprint.route('/', methods=['GET']) def index_get() -> Response: email_address = session.get('username') diff --git a/undercover/templates/writing.jinja2 b/undercover/templates/writing.jinja2 index 9ad8ef1..b2636bd 100644 --- a/undercover/templates/writing.jinja2 +++ b/undercover/templates/writing.jinja2 @@ -63,6 +63,7 @@
{% if username %} {{ render_field(form.letterName, onchange="window.location = '/?letter_name=' + this.options[this.value - 1].label") }} + + {% endif %} {{ render_field(form.username) }} {{ render_field(form.company) }}