Refactor index_get() with early returns.

This commit is contained in:
Sage Vaillancourt 2022-09-27 22:50:12 -04:00
parent 1b32206a23
commit 58bebc2109
1 changed files with 30 additions and 25 deletions

View File

@ -109,16 +109,21 @@ def logout():
@writing_blueprint.route('/', methods=['GET']) @writing_blueprint.route('/', methods=['GET'])
def index_get(): def index_get():
email_address = session.get('username') email_address = session.get('username')
if not email_address:
return render_index()
form = CLForm() form = CLForm()
if email_address:
user = db.get_user(email_address) user = db.get_user(email_address)
letters = db.get_user_letters(user.id) letters = db.get_user_letters(user.id)
if len(letters) > 0: if len(letters) == 0:
return render_index()
letter_names = [(i + 1, letter.title) for i, letter in enumerate(letters)] letter_names = [(i + 1, letter.title) for i, letter in enumerate(letters)]
form.letterName.choices = letter_names form.letterName.choices = letter_names
form.letterName.data = 1 form.letterName.data = 1
selected_letter = request.args.get('letter_name') selected_letter = request.args.get('letter_name')
if selected_letter: if selected_letter:
for i, letter in enumerate(letters): for i, letter in enumerate(letters):
if letter.title == selected_letter: if letter.title == selected_letter: