From 6207989c03a375ab4a1a1ff3f7ae7ca32606ca01 Mon Sep 17 00:00:00 2001 From: bwc9876 Date: Mon, 25 Oct 2021 14:41:26 -0400 Subject: [PATCH] Fixed colspan filter --- Instructor/forms.py | 4 ++-- .../static/js/rubrics/rubric-create-widget.js | 2 +- Instructor/templatetags/rubric_tags.py | 14 ++++++++++++++ Instructor/views.py | 4 ++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Instructor/forms.py b/Instructor/forms.py index 013100a..129b74f 100644 --- a/Instructor/forms.py +++ b/Instructor/forms.py @@ -172,9 +172,9 @@ class RubricForm(ModelForm): @staticmethod def explain_json_error(error: ValidationError) -> str: """ - In the event of an error when parsing the JSON for the rubric, this function will exaplin what is wrong + In the event of an error when parsing the JSON for the rubric, this function will explain what is wrong - :param error: The ValidationError that occured + :param error: The ValidationError that occurred :type error: ValidationError :return: An explanation on what is wrong with the JSON :rtype: str diff --git a/Instructor/static/js/rubrics/rubric-create-widget.js b/Instructor/static/js/rubrics/rubric-create-widget.js index 5d714e2..8a4c419 100644 --- a/Instructor/static/js/rubrics/rubric-create-widget.js +++ b/Instructor/static/js/rubrics/rubric-create-widget.js @@ -1,5 +1,5 @@ /** - * This file is used when creating or editting a rubric + * This file is used when creating or editing a rubric */ let table = undefined; diff --git a/Instructor/templatetags/rubric_tags.py b/Instructor/templatetags/rubric_tags.py index bb1bcbb..1418d5a 100644 --- a/Instructor/templatetags/rubric_tags.py +++ b/Instructor/templatetags/rubric_tags.py @@ -39,6 +39,20 @@ def get_cells(row: RubricRow) -> QuerySet: return RubricCell.objects.filter(parent_row=row) +@register.filter(name='colspan') +def get_colspan(rubric: Rubric) -> int: + """ + This filter gets the colspan needed to represent a Rubric as a table + :param rubric: The rubric to check + :type rubric: Rubric + :returns: The colspan needed for the "scores" th element in the table + :rtype: int + """ + + return max([RubricCell.objects.filter(parent_row=row).count() + for row in RubricRow.objects.filter(parent_rubric=rubric)]) + + @register.filter(name='is_score') def is_score(cell: RubricCell, review: Review): """ diff --git a/Instructor/views.py b/Instructor/views.py index ae5d1a5..88e2040 100644 --- a/Instructor/views.py +++ b/Instructor/views.py @@ -148,7 +148,7 @@ class RubricListView(LoginRequiredMixin, IsSuperUserMixin, ListView): """ This View lists the Rubric in the database - :cvar template_name: The tempalte to render and pass to the user + :cvar template_name: The template to render and pass to the user :cvar model: The model django will list and show to the user :cvar context_object_name: The name of the list that is passed to the template as context """ @@ -184,7 +184,7 @@ class RubricEditView(LoginRequiredMixin, IsSuperUserMixin, FormNameMixin, FormAl :cvar success_url: The url to go to if the edit was successful :cvar template_name: The template to render and return to the user :cvar form_name: The name of the form to display as the Page Header - :cvar success_message: The message that will appear as an alert when the editting is done + :cvar success_message: The message that will appear as an alert when the editing is done """ form_class = forms.RubricForm -- knotmirror 0.0.1