|
19 | 19 | from authorization.permissions import ACCESS |
20 | 20 | from course.viewbase import CourseInstanceBaseView, CourseInstanceMixin |
21 | 21 | from course.models import ( |
| 22 | + CourseModule, |
22 | 23 | Enrollment, |
23 | 24 | USERTAG_EXTERNAL, |
24 | 25 | USERTAG_INTERNAL, |
25 | 26 | ) |
26 | 27 | from deviations.models import MaxSubmissionsRuleDeviation |
27 | 28 | from exercise.cache.points import CachedPoints |
| 29 | +from exercise.exercise_models import BaseExercise |
28 | 30 | from lib.helpers import settings_text, extract_form_errors |
29 | 31 | from lib.viewbase import BaseRedirectView, BaseFormView, BaseView |
30 | 32 | from notification.models import Notification |
@@ -530,3 +532,61 @@ def form_valid(self, form): |
530 | 532 | def form_invalid(self, form): |
531 | 533 | messages.error(self.request, _('FAILURE_SAVING_CHANGES')) |
532 | 534 | return super().form_invalid(form) |
| 535 | + |
| 536 | +class SubmissionConversion(SubmissionMixin, BaseRedirectView): |
| 537 | + """ |
| 538 | + A POST-only view that updates a student's late or unofficial submission |
| 539 | + to normal submission. Changed the status and remove the penalty |
| 540 | + """ |
| 541 | + def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: |
| 542 | + self.submission = self.get_submission_object() |
| 543 | + self.submission.convert_late_submission() |
| 544 | + self.submission.save() |
| 545 | + return self.redirect(self.submission.get_inspect_url()) |
| 546 | + |
| 547 | + |
| 548 | +class SubmissionConversionByModule(CourseInstanceMixin, BaseRedirectView): |
| 549 | + """ |
| 550 | + A POST-only view that by module bulks updates a student's late or unofficial submission |
| 551 | + to normal submission. Changed the status and remove the penalty |
| 552 | + """ |
| 553 | + |
| 554 | + user_kw = 'user_id' |
| 555 | + module_kw = 'module_id' |
| 556 | + access_mode = ACCESS.ASSISTANT |
| 557 | + |
| 558 | + def get_course_module_object(self): |
| 559 | + return get_object_or_404( |
| 560 | + CourseModule, |
| 561 | + id=self.kwargs[self.module_kw], |
| 562 | + course_instance=self.instance |
| 563 | + ) |
| 564 | + |
| 565 | + def get_resource_objects(self): |
| 566 | + self.kwargs[self.user_kw] = self.request.POST[self.user_kw], |
| 567 | + self.kwargs[self.user_kw] = self.kwargs[self.user_kw][0] |
| 568 | + self.kwargs[self.module_kw] = self.request.POST[self.module_kw] |
| 569 | + super().get_resource_objects() |
| 570 | + |
| 571 | + #getting module and user by id. |
| 572 | + self.module = get_object_or_404( |
| 573 | + CourseModule, |
| 574 | + id=self.kwargs[self.module_kw]) |
| 575 | + |
| 576 | + self.student = get_object_or_404( |
| 577 | + User, |
| 578 | + id=self.kwargs[self.user_kw], |
| 579 | + ) |
| 580 | + |
| 581 | + def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: |
| 582 | + profile = self.student.userprofile |
| 583 | + exercises = BaseExercise.objects.filter(course_module=self.module) |
| 584 | + |
| 585 | + for exercise in exercises: |
| 586 | + submissions = exercise.get_submissions_for_student(self.student.userprofile, exclude_errors=True) |
| 587 | + for submission in submissions: |
| 588 | + submission.convert_late_submission() |
| 589 | + submission.save() |
| 590 | + |
| 591 | + link = reverse('user-results', kwargs={'user_id': profile.id, **self.instance.get_url_kwargs()}) |
| 592 | + return self.redirect(link) |
0 commit comments