Skip to content

Commit

Permalink
Fix show_zero_points_immediately showing previous attempt's points
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelGusse authored and ihalaij1 committed Dec 10, 2024
1 parent 7524007 commit 5338a7c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
11 changes: 8 additions & 3 deletions exercise/cache/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ class ExercisePoints(LearningObjectPoints):
personal_deadline_has_penalty: Optional[bool]
personal_max_submissions: Optional[int]
feedback_reveal_time: Optional[datetime.datetime]
show_zero_points_immediately: Optional[bool]

best_submission = RevealableAttribute[Optional[SubmissionEntry]]()

Expand Down Expand Up @@ -638,9 +639,12 @@ def get(cls, # pylint: disable=arguments-renamed

def post_build(self, precreated: ProxyManager):
super().post_build(precreated)

for submission in self.submissions:
submission.reveal(self._modifiers[0])
if not self.show_zero_points_immediately:
submission.reveal(self._modifiers[0])
else:
if submission._true_points == 0:
submission.feedback_revealed = True

# pylint: disable-next=too-many-locals
def _generate_data( # noqa: MC0001
Expand Down Expand Up @@ -697,6 +701,7 @@ def _generate_data( # noqa: MC0001
self.notified = False
self.unseen = False
self.model_answer_modules = []
self.show_zero_points_immediately = False

# Augment submission data.
final_submission = None
Expand Down Expand Up @@ -731,7 +736,6 @@ def _generate_data( # noqa: MC0001
group_id = group.id
else:
group_id = 0

submission_entry = SubmissionEntry(
id = submission.id,
exercise = self,
Expand Down Expand Up @@ -817,6 +821,7 @@ def _generate_data( # noqa: MC0001
# Check the reveal rule now that all submissions for the exercise have been iterated.
reveal_rule = prefetched_data.get_reveal_rule(lobj_id)
state = ExerciseRevealState(self)
self.show_zero_points_immediately = reveal_rule.show_zero_points_immediately
is_revealed = reveal_rule.is_revealed(state)
reveal_time = reveal_rule.get_reveal_time(state)
else:
Expand Down
3 changes: 0 additions & 3 deletions exercise/reveal_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ def is_revealed(self, state: 'BaseRevealState', time: Optional[datetime.datetime
If a time is provided, visibility is checked for that specific time.
Otherwise, the current time is used.
"""

if self.show_zero_points_immediately and state.get_points() == 0:
return True
if self.trigger == RevealRule.TRIGGER.MANUAL:
return self.currently_revealed
if self.trigger == RevealRule.TRIGGER.IMMEDIATE:
Expand Down
8 changes: 6 additions & 2 deletions exercise/templates/exercise/_points_badge.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
{% if difficulty %}
<span class="difficulty">{{ difficulty }}</span>
{% endif %}
<span class="badge{% if submitted and official %} {% if feedback_revealed %}{% if full_score %}badge-success{% elif passed %}badge-warning{% else %}badge-danger{% endif %}{% endif %}{% if unconfirmed %} unconfirmed-points{% endif %}{% endif %}{% if classes %} {{ classes }}{% endif %}"
<span class="badge{% if submitted and official %} {% if feedback_revealed %}{% if full_score %}badge-success{% elif passed %}badge-warning{% else %}badge-danger{% endif %}{% endif %}{% if unconfirmed %} unconfirmed-points{% endif %}{% endif %}{% if classes %} {{ classes }}{% elif show_zero_points_immediately and best_submission_true_points == 0 %}badge-danger{% endif %}"
data-toggle="tooltip" data-placement="bottom"
title="{% if not feedback_revealed %}{{ feedback_hidden_description }}{% elif not official %}{% if unofficial_submission_type == 'limit_exceeded' %}{% translate 'LIMIT_EXCEEDED' %}{% elif unofficial_submission_type == 'deadline_passed' %}{% translate 'DEADLINE_PASSED' %}{% else %}{% translate 'UNOFFICIAL_DESCRIPTION' %}{% endif %}{% elif passed %}{% if required > 0 %}{% translate 'PASSED' %}{% endif %}{% elif missing_points %}{% blocktranslate trimmed with points=required %}POINTS_REQUIRED_TO_PASS -- {{ points }}{% endblocktranslate %}{% elif submitted %}{% translate 'REQUIRED_EXERCISES_NOT_PASSED' %}{% endif %}">
{{ formatted_points }} / {{ max }}
{% if show_zero_points_immediately and best_submission_true_points == 0 %}
0 / {{ max }}
{% else %}
{{ formatted_points }} / {{ max }}
{% endif %}
</span>
{% endif %}
7 changes: 7 additions & 0 deletions exercise/templatetags/exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,13 @@ def _points_data(
# All the different cached points entries
if isinstance(obj, ExercisePoints):
points = obj.official_points
if obj.best_submission:
best_submission_true_points = obj.best_submission._true_points
else:
best_submission_true_points = None
else:
points = obj.points
best_submission_true_points = None

max_points = getattr(obj, 'max_points', 0)
required = getattr(obj, 'points_to_pass', 0)
Expand Down Expand Up @@ -228,6 +233,8 @@ def _points_data(
'module_goal_points': module_goal_points,
'module_goal_percentage': module_goal_percentage,
'module_goal_achieved': module_goal_achieved,
'show_zero_points_immediately': getattr(obj, 'show_zero_points_immediately', False),
'best_submission_true_points': best_submission_true_points,
}
reveal_time = getattr(obj, 'feedback_reveal_time', None)

Expand Down

0 comments on commit 5338a7c

Please sign in to comment.