Fix issue where dynamic challenges break if the decay is 0 (#2255)

* Fix issue where dynamic challenges break if the decay is 0
* Prevent users from adding a decay limit of 0 to dynamic value challenges
This commit is contained in:
Kevin Chung
2023-02-08 13:22:16 -05:00
committed by GitHub
parent 0f0064535c
commit 68c3438474
3 changed files with 7 additions and 2 deletions

View File

@@ -69,6 +69,11 @@ class DynamicValueChallenge(BaseChallenge):
# We subtract -1 to allow the first solver to get max point value
solve_count -= 1
# Handle situations where admins have entered a 0 decay
# This is invalid as it can cause a division by zero
if challenge.decay == 0:
challenge.decay = 1
# It is important that this calculation takes into account floats.
# Hence this file uses from __future__ import division
value = (

View File

@@ -25,7 +25,7 @@
The amount of solves before the challenge reaches its minimum value
</small>
</label>
<input type="number" class="form-control" name="decay" placeholder="Enter decay limit" required>
<input type="number" class="form-control" name="decay" min="1" placeholder="Enter decay limit" required>
</div>
<div class="form-group">

View File

@@ -25,7 +25,7 @@
The amount of solves before the challenge reaches its minimum value
</small>
</label>
<input type="number" class="form-control chal-decay" name="decay" value="{{ challenge.decay }}" required>
<input type="number" class="form-control chal-decay" min="1" name="decay" value="{{ challenge.decay }}" required>
</div>
<div class="form-group">