Skip to content

Commit

Permalink
Fix messages disappearing after first submission
Browse files Browse the repository at this point in the history
There was a bug that caused exercise messages such as "Staff can submit
assignments without enrolling" and "Only your last submission will be graded"
to disappear forever after the student makes their first submission. This was
caused by chapter.js, which replaced the entire exercise container, including
the message area, when the last submission was loaded and displayed. This has
been fixed and now the messages are not removed. Additionally, the "Only your
last submission will be graded" message is now added in
`ExerciseView.submission_check` instead of `ExerciseView.get`, so it remains
visible after clicking the submit button.

Fixes #881
  • Loading branch information
skulonen authored and markkuriekkinen committed Oct 20, 2021
1 parent 8a852f9 commit 4312c99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 7 additions & 5 deletions exercise/static/exercise/chapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,15 +793,17 @@
exercise.hideLoader();

if (!exercise.active_element) {
var f = exercise.element.find(exercise.settings.response_selector)
.empty().append(
$(data).filter(exercise.settings.exercise_selector).contents()
);
const responseElement = exercise.element.find(exercise.settings.response_selector);
// Remove only the exercise content, not the alerts above it
responseElement.children().not('.alert').remove();
responseElement.append(
$(data).filter(exercise.settings.exercise_selector).contents()
);
exercise.dom_element.dispatchEvent(
new CustomEvent("aplus:exercise-loaded",
{bubbles: true, detail: {type: exercise.exercise_type}}));
// TODO: remove magic constant (variable defined in group.js)
f.removeClass('group-augmented');
responseElement.removeClass('group-augmented');
exercise.bindFormEvents(exercise.element);
exercise.dom_element.dispatchEvent(
new CustomEvent("aplus:exercise-ready",
Expand Down
5 changes: 3 additions & 2 deletions exercise/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
SUBMIT_STATUS.NOT_ENROLLED,
]
should_enroll = submission_status == SUBMIT_STATUS.NOT_ENROLLED
if self.exercise.grading_mode == BaseExercise.GRADING_MODE.LAST:
messages.warning(request, _('ONLY_YOUR_LAST_SUBMISSION_WILL_BE_GRADED'))

if (self.exercise.status == LearningObject.STATUS.MAINTENANCE
or self.module.status == CourseModule.STATUS.MAINTENANCE):
Expand Down Expand Up @@ -210,6 +208,9 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
page=page, students=students, submission=new_submission))

def submission_check(self, error=False, request=None):
if self.exercise.grading_mode == BaseExercise.GRADING_MODE.LAST:
# Add warning about the grading mode.
messages.warning(self.request, _('ONLY_YOUR_LAST_SUBMISSION_WILL_BE_GRADED'))
if not self.profile:
issue = _('SUBMISSION_MUST_SIGN_IN_AND_ENROLL_TO_SUBMIT_EXERCISES')
messages.error(self.request, issue)
Expand Down

0 comments on commit 4312c99

Please sign in to comment.