[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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user