Skip to content

Commit

Permalink
small readability changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmvfb committed Aug 9, 2023
1 parent 9b3fcdc commit 8438776
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions english_exercises_app/exercises/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ def populate_exercise_form(self, data: QueryDict or dict) -> dict:
"""

if isinstance(data, QueryDict): # handling post request
form = TypeInExercise(data)
if data.get("exercise_type") == "blanks":
form = BlanksExercise(data)
form = (
TypeInExercise(data)
if data.get("exercise_type") != "blanks"
else BlanksExercise(data)
)
return form

# handling get request
Expand Down Expand Up @@ -183,10 +185,10 @@ def post(self, request):
form.save(user=request.user)

if user_answer == correct_answer:
hide_correct = True
hide_correct = (
True if form.cleaned_data["exercise_type"] != "blanks" else False
)
messages.success(request, _("Correct!"))
if form.cleaned_data["exercise_type"] == "blanks":
hide_correct = False
else:
hide_correct = False
messages.error(request, _("Sorry, your answer is incorrect"))
Expand Down

0 comments on commit 8438776

Please sign in to comment.