Skip to content

Commit

Permalink
Merge pull request #199 from PremierLangage/0.5.2
Browse files Browse the repository at this point in the history
0.5.2
  • Loading branch information
Pavell94000 authored Feb 26, 2019
2 parents a9a5243 + 9daed08 commit 9c28dc6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions server/serverpl/playexo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,10 @@ class Answer(models.Model):

@staticmethod
def highest_grade(pl, user):
answers = Answer.objects.filter(pl=pl, user=user).order_by("-grade")
return answers[0] if answers else None
null = list(Answer.objects.filter(pl=pl, user=user).filter(grade__isnull=True))
answers = list(Answer.objects.filter(pl=pl, user=user)
.filter(grade__isnull=False).order_by("-grade"))
return (answers + null)[0] if (answers + null) else None


@staticmethod
Expand All @@ -503,8 +505,8 @@ def last(pl, user):
@staticmethod
def pl_state(pl, user):
"""Return the state of the answer with the highest grade."""
answers = Answer.objects.filter(user=user, pl=pl).order_by("-grade")
return State.by_grade(answers[0].grade if answers else ...)
answer = Answer.highest_grade(pl, user)
return State.by_grade(answer.grade if answer else ...)


@staticmethod
Expand Down

0 comments on commit 9c28dc6

Please sign in to comment.