Skip to content

Commit

Permalink
Fix incorrect deadline in ModuleRevealState when it has no exercises
Browse files Browse the repository at this point in the history
When ModuleRevealState has no exercises (that is, the corresponding
course module contains no exercises), then it must return
the module's deadline instead of `None` in the methods
`get_deadline()` and `get_latest_deadline()`.
`None` value prevents deadline-triggered reveal rules from working,
that is, the chapter model solution for the course module would
never be revealed when the deadline trigger is used.

In addition, this commit slightly optimizes ModuleRevealState.
In `get_latest_deadline()`, all exercises belong to the same
course module, thus their common deadlines are identical
(the module's deadline).
  • Loading branch information
markkuriekkinen authored and ihalaij1 committed Dec 22, 2023
1 parent f900b0f commit 8757934
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions exercise/reveal_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
from .cache.points import LearningObjectPoints, ModulePoints, ExercisePoints


def _get_exercise_common_deadlines(exercise: ExercisePoints) -> List[datetime.datetime]:
deadlines = [exercise.closing_time]
if exercise.late_allowed and exercise.late_percent > 0:
deadlines.append(exercise.late_time)
def _get_exercise_common_deadlines(
exercise_or_module: Union[ExercisePoints, ModulePoints],
) -> List[datetime.datetime]:
deadlines = [exercise_or_module.closing_time]
if exercise_or_module.late_allowed and exercise_or_module.late_percent > 0:
deadlines.append(exercise_or_module.late_time)
return deadlines


Expand Down Expand Up @@ -156,9 +158,8 @@ def get_latest_deadline(self) -> Optional[datetime.datetime]:
deadlines = _get_exercise_common_deadlines(self.module)
exercise_dict = {}
for exercise in self.exercises:
deadlines.extend(_get_exercise_common_deadlines(exercise))
exercise_dict[exercise.id] = exercise
if not self.max_deviation_fetched:
if not self.max_deviation_fetched and self.exercises:
self.max_deviation = (
DeadlineRuleDeviation.objects
.filter(exercise__course_module_id=self.module_id)
Expand Down

0 comments on commit 8757934

Please sign in to comment.