From 31f6737f9223352dc08d715bd17db48075c6d991 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Thu, 29 Sep 2022 12:54:59 -0400 Subject: [PATCH] Correct letter_choices behavior --- undercover/routes.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/undercover/routes.py b/undercover/routes.py index 3ee1afd..2586ee8 100644 --- a/undercover/routes.py +++ b/undercover/routes.py @@ -21,7 +21,9 @@ class CLForm(Form): def __init__(self, form: dict[str, str] = None, email_address: str = None, **kwargs): super().__init__(form, **kwargs) if email_address: - self.letterName.choices = letter_choices(email_address) + user = db.get_user(email_address) + letters = db.get_user_letters(user.id) + self.letterName.choices = letter_choices(letters) letterName = SelectField( 'Letter Name:', @@ -144,9 +146,7 @@ def add_letter() -> Response: return redirect(f'/?letter_name={new_letter_name}') -def letter_choices(email_address: str) -> list[(int, str)]: - user = db.get_user(email_address) - letters = db.get_user_letters(user.id) +def letter_choices(letters: list[db.Letter]) -> list[(int, str)]: if len(letters) == 0: return [] @@ -160,7 +160,9 @@ def index_get() -> Response: return render_index() form = CLForm() - letter_names = letter_choices(email_address) + user = db.get_user(email_address) + letters = db.get_user_letters(user.id) + letter_names = letter_choices(letters) if len(letter_names) == 0: return render_index() form.letterName.choices = letter_names