Correct letter_choices behavior
This commit is contained in:
parent
ef0b6503cb
commit
31f6737f92
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue