From 5777ef5e82642489b668904fd4ff1118d3773cfe Mon Sep 17 00:00:00 2001 From: Murhu Markus Date: Wed, 22 May 2024 12:01:17 +0300 Subject: [PATCH] Remove unneeded submission tagging form Submission tags are created through the inspect submission UI so the form is unnecessary, as well as the associated template. Also checked submission tagging add- and delete forms to verify the tag comes from the accessed course instance. --- edit_course/course_forms.py | 14 ---------- .../edit_course/submissiontagging_add.html | 28 ------------------- exercise/views.py | 28 +++---------------- locale/en/LC_MESSAGES/django.po | 5 ---- locale/fi/LC_MESSAGES/django.po | 5 ---- 5 files changed, 4 insertions(+), 76 deletions(-) delete mode 100644 edit_course/templates/edit_course/submissiontagging_add.html diff --git a/edit_course/course_forms.py b/edit_course/course_forms.py index ce5a1f2f3..95c404dfb 100644 --- a/edit_course/course_forms.py +++ b/edit_course/course_forms.py @@ -15,7 +15,6 @@ from course.models import LearningObjectCategory, CourseModule, CourseInstance, UserTag, SubmissionTag from course.sis import get_sis_configuration, StudentInfoSystem from exercise.models import CourseChapter -from exercise.submission_models import SubmissionTagging from lib.validators import generate_url_key_validator from lib.fields import UsersSearchSelectField from lib.widgets import DateTimeLocalInput @@ -444,19 +443,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.fields['user'].queryset = course_instance.get_student_profiles() -class SubmissionTaggingForm(forms.ModelForm): - class Meta(ColorTagForm.Meta): - model = SubmissionTagging - fields = [ - 'tag', - 'submission', - ] - labels = { - 'tag': _('LABEL_SUBMISSION_TAG'), - 'submission': _('LABEL_SUBMISSION'), - } - - class GitmanagerForm(forms.Form): key = forms.SlugField( label=_('LABEL_KEY'), diff --git a/edit_course/templates/edit_course/submissiontagging_add.html b/edit_course/templates/edit_course/submissiontagging_add.html deleted file mode 100644 index ae9ad2b7e..000000000 --- a/edit_course/templates/edit_course/submissiontagging_add.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "edit_course/edit_course_base.html" %} -{% load i18n %} -{% load bootstrap %} -{% load course %} -{% load editcourse %} -{% load static %} - -{% block editbreadcrumblist %} -{{ block.super }} -
  • {% translate "SUBMISSION_TAGS" %}
  • -
  • {% translate "ADD_NEW_SUBMISSION_TAGGING" %}
  • -{% endblock %} -{% block view_tag %}edit-course,course-submission-tags{% endblock %} - -{% block coursecontent %} -
    -
    - {% csrf_token %} - {% translate "ADD_NEW_SUBMISSION_TAGGING" %} - {{ form|bootstrap_horizontal }} -
    -
    - - {% translate "CANCEL" %} -
    -
    -
    -{% endblock %} diff --git a/exercise/views.py b/exercise/views.py index f143a50cf..a5487afb6 100644 --- a/exercise/views.py +++ b/exercise/views.py @@ -11,13 +11,10 @@ from django.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.csrf import csrf_exempt from django.db import DatabaseError -from django.views.generic import CreateView from authorization.permissions import ACCESS from course.models import CourseModule, SubmissionTag from course.viewbase import CourseInstanceBaseView, EnrollableViewMixin -from edit_course.course_forms import SubmissionTaggingForm -from edit_course.views import SubmissionTagMixin from lib.helpers import query_dict_to_list_of_tuples, safe_file_name, is_ajax from lib.remote_page import RemotePageNotFound, request_for_response from lib.viewbase import BaseRedirectMixin, BaseView @@ -46,11 +43,7 @@ class TableOfContentsView(CourseInstanceBaseView): class ResultsView(TableOfContentsView): template_name = "exercise/results.html" - -class SubmissionTaggingAddView(SubmissionTagMixin, CreateView): - form_class = SubmissionTaggingForm - template_name = "edit_course/submissiontagging_add.html" - pk_url_kwarg = "subtag_id" +class SubmissionTaggingAddView(CourseInstanceBaseView): access_mode = ACCESS.ASSISTANT def post(self, request, *args, **kwargs): @@ -59,7 +52,7 @@ def post(self, request, *args, **kwargs): # Get the Submission and SubTag objects using these ids submission = Submission.objects.get(id=submission_id) - subtag = SubmissionTag.objects.get(id=subtag_id) + subtag = SubmissionTag.objects.get(id=subtag_id, course_instance=self.instance) # Create a new SubmissionTagging object SubmissionTagging.objects.create(submission=submission, tag=subtag) @@ -67,15 +60,8 @@ def post(self, request, *args, **kwargs): # Redirect back to the previous page return redirect(request.META.get('HTTP_REFERER', '/')) - def __init__(self, *args, **kwargs): - self.instance = kwargs.pop('instance', None) - super().__init__(*args, **kwargs) - -class SubmissionTaggingRemoveView(SubmissionTagMixin, CreateView): - form_class = SubmissionTaggingForm - template_name = "edit_course/submissiontagging_add.html" - pk_url_kwarg = "subtag_id" +class SubmissionTaggingRemoveView(CourseInstanceBaseView): access_mode = ACCESS.ASSISTANT def post(self, request, *args, **kwargs): @@ -84,7 +70,7 @@ def post(self, request, *args, **kwargs): # Get the Submission and SubTag objects using these ids submission = Submission.objects.get(id=submission_id) - subtag = SubmissionTag.objects.get(id=subtag_id) + subtag = SubmissionTag.objects.get(id=subtag_id, course_instance=self.instance) # Delete SubmissionTagging object SubmissionTagging.objects.filter(submission=submission, tag=subtag).delete() @@ -92,16 +78,10 @@ def post(self, request, *args, **kwargs): # Redirect back to the previous page return redirect(request.META.get('HTTP_REFERER', '/')) - def __init__(self, *args, **kwargs): - self.instance = kwargs.pop('instance', None) - super().__init__(*args, **kwargs) - - class ExerciseInfoView(ExerciseBaseView): ajax_template_name = "exercise/_exercise_info.html" - class ExerciseView(BaseRedirectMixin, ExerciseBaseView, EnrollableViewMixin): template_name = "exercise/exercise.html" ajax_template_name = "exercise/exercise_plain.html" diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index 475775a3e..4091ce6fb 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -1457,7 +1457,6 @@ msgstr "Tags" #: edit_course/templates/edit_course/submissiontag_delete.html #: edit_course/templates/edit_course/submissiontag_edit.html #: edit_course/templates/edit_course/submissiontag_list.html -#: edit_course/templates/edit_course/submissiontagging_add.html msgid "SUBMISSION_TAGS" msgstr "Submission tags" @@ -2911,10 +2910,6 @@ msgstr "No student tags." msgid "ADD_NEW_USER_TAGGING" msgstr "Add new user tagging" -#: edit_course/templates/edit_course/submissiontagging_add.html -msgid "ADD_NEW_SUBMISSION_TAGGING" -msgstr "Add new submission tagging" - #: exercise/forms.py exercise/templates/exercise/staff/_assessment_panel.html msgid "ADD_TAGGING" msgstr "Add tagging" diff --git a/locale/fi/LC_MESSAGES/django.po b/locale/fi/LC_MESSAGES/django.po index b39a0e861..eaedc0ef0 100644 --- a/locale/fi/LC_MESSAGES/django.po +++ b/locale/fi/LC_MESSAGES/django.po @@ -1465,7 +1465,6 @@ msgstr "Merkinnät" #: edit_course/templates/edit_course/submissiontag_delete.html #: edit_course/templates/edit_course/submissiontag_edit.html #: edit_course/templates/edit_course/submissiontag_list.html -#: edit_course/templates/edit_course/submissiontagging_add.html msgid "SUBMISSION_TAGS" msgstr "Palautusmerkinnät" @@ -2926,10 +2925,6 @@ msgstr "Ei opiskelijamerkintöjä." msgid "ADD_NEW_USER_TAGGING" msgstr "Merkitse opiskelijoita" -#: edit_course/templates/edit_course/submissiontagging_add.html -msgid "ADD_NEW_SUBMISSION_TAGGING" -msgstr "Merkitse palautuksia" - #: exercise/forms.py exercise/templates/exercise/staff/_assessment_panel.html msgid "ADD_TAGGING" msgstr "Lisää merkintä"