[FIX] gamification: tolerate invalid definitions

If a goal definition with a target goal of 0 and "higher the better",
instead of dividing by 0, set a progress of 0% (it is not possible to
compute the progress)

Task id: 2057898
This commit is contained in:
Martin Trigaux
2019-08-26 10:03:54 +00:00
parent 712808581d
commit 6ca81cd868
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -743,7 +743,7 @@ class Challenge(models.Model):
all_reached = False
if goal.definition_condition == 'higher':
# can be over 100
total_completeness += 100.0 * goal.current / goal.target_goal
total_completeness += (100.0 * goal.current / goal.target_goal) if goal.target_goal else 0
elif goal.state == 'reached':
# for lower goals, can not get percentage so 0 or 100
total_completeness += 100
+1 -1
View File
@@ -195,7 +195,7 @@ class Goal(models.Model):
if goal.current >= goal.target_goal:
goal.completeness = 100.0
else:
goal.completeness = round(100.0 * goal.current / goal.target_goal, 2)
goal.completeness = round(100.0 * goal.current / goal.target_goal, 2) if goal.target_goal else 0
elif goal.current < goal.target_goal:
# a goal 'lower than' has only two values possible: 0 or 100%
goal.completeness = 100.0