From 64055d94d45b85c0d8c52f537e9842afe20b455b Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 11 Nov 2024 17:28:54 +0000 Subject: [PATCH 01/15] feat: add filtering for proofread fields - manuscript_full_text_proofread, manuscript_full_text_std_proofread, volpiano_proofread - check if user is proofreader - add form for proofread choicefields --- .../cantusdb_project/main_app/views/source.py | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/django/cantusdb_project/main_app/views/source.py b/django/cantusdb_project/main_app/views/source.py index bf81e10e4..b9904b7f2 100644 --- a/django/cantusdb_project/main_app/views/source.py +++ b/django/cantusdb_project/main_app/views/source.py @@ -18,7 +18,11 @@ TemplateView, ) -from main_app.forms import SourceCreateForm, SourceEditForm +from main_app.forms import ( + SourceCreateForm, + SourceEditForm, + SourceBrowseChantsProofreadForm, +) from main_app.models import ( Century, Chant, @@ -34,6 +38,7 @@ user_can_edit_source, user_can_view_source, user_can_manage_source_editors, + user_can_proofread_source, ) from main_app.views.chant import ( get_feast_selector_options, @@ -54,6 +59,7 @@ class SourceBrowseChantsView(ListView): ``search_text``: Filters by text of Chant ``genre``: Filters by genre of Chant ``folio``: Filters by folio of Chant + ``manuscript_full_text_proofread``: Filters if """ model = Chant @@ -84,8 +90,17 @@ def get_queryset(self): folio = self.request.GET.get("folio") search_text = self.request.GET.get("search_text") + # proofread fields filter + manuscript_full_text_proofread = self.request.GET.get( + "manuscript_full_text_proofread" + ) + manuscript_full_text_std_proofread = self.request.GET.get( + "manuscript_full_text_std_proofread" + ) + volpiano_proofread = self.request.GET.get("volpiano_proofread") + # get all chants in the specified source - chants = source.chant_set.select_related("feast", "service", "genre") + chants: QuerySet = source.chant_set.select_related("feast", "service", "genre") # filter the chants with optional search params if feast_id: chants = chants.filter(feast__id=feast_id) @@ -100,6 +115,18 @@ def get_queryset(self): | Q(incipit__icontains=search_text) | Q(manuscript_full_text__icontains=search_text) ) + # Apply proofreading filters if they are set + if manuscript_full_text_proofread: + chants = chants.filter( + manuscript_full_text_std_proofread=manuscript_full_text_proofread + ) + if manuscript_full_text_std_proofread: + chants = chants.filter( + manuscript_full_text_proofread=manuscript_full_text_std_proofread + ) + if volpiano_proofread: + chants = chants.filter(volpiano_proofread=volpiano_proofread) + return chants.order_by("folio", "c_sequence") def get_context_data(self, **kwargs): @@ -134,6 +161,7 @@ def get_context_data(self, **kwargs): user = self.request.user context["user_can_edit_chant"] = user_can_edit_chants_in_source(user, source) + context["user_can_proofread_source"] = user_can_proofread_source(user, source) chants_in_source: QuerySet[Chant] = source.chant_set if chants_in_source.count() == 0: @@ -165,6 +193,9 @@ def get_context_data(self, **kwargs): # the options for the feast selector on the right, same as the source detail page context["feasts_with_folios"] = get_feast_selector_options(source) + context["proofread_filter_form"] = SourceBrowseChantsProofreadForm( + self.request.GET or None + ) return context From 8a26d9261319dc6e6dcf907a3b9fb04614eed8da Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 11 Nov 2024 17:29:39 +0000 Subject: [PATCH 02/15] feat: add form for proofread field choices --- django/cantusdb_project/main_app/forms.py | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/django/cantusdb_project/main_app/forms.py b/django/cantusdb_project/main_app/forms.py index ad150622b..b22b87114 100644 --- a/django/cantusdb_project/main_app/forms.py +++ b/django/cantusdb_project/main_app/forms.py @@ -42,6 +42,15 @@ (False, "Partial inventory"), ) +# Define choices for Chant model's +# various proofreading fields: manuscript_full_text_std_proofread, +# manuscript_full_text_proofread, volpiano_proofread +PROOFREAD_CHOICES = [ + (None, "Any"), + (True, "Yes"), + (False, "No"), +] + class NameModelChoiceField(forms.ModelChoiceField): """ @@ -520,6 +529,28 @@ class Meta: ) +class SourceBrowseChantsProofreadForm(forms.Form): + manuscript_full_text_std_proofread = forms.ChoiceField( + label="Full text as in Source (standardized spelling) proofread", + choices=PROOFREAD_CHOICES, + widget=forms.RadioSelect, + required=False, + ) + manuscript_full_text_proofread = forms.ChoiceField( + label="Full text as in Source (source spelling)", + choices=PROOFREAD_CHOICES, + widget=forms.RadioSelect, + required=False, + ) + + volpiano_proofread = forms.ChoiceField( + label="Volpiano Proofread", + choices=PROOFREAD_CHOICES, + widget=forms.RadioSelect, + required=False, + ) + + class SequenceEditForm(forms.ModelForm): class Meta: model = Sequence From 522db41e369939bc7fba0f8cdbdc149a7bba3f62 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 11 Nov 2024 17:31:14 +0000 Subject: [PATCH 03/15] feat: add radioselect widgets for chant proofreading filters --- .../main_app/templates/browse_chants.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/django/cantusdb_project/main_app/templates/browse_chants.html b/django/cantusdb_project/main_app/templates/browse_chants.html index 771aceac0..1b80a0b58 100644 --- a/django/cantusdb_project/main_app/templates/browse_chants.html +++ b/django/cantusdb_project/main_app/templates/browse_chants.html @@ -58,6 +58,21 @@

Browse Chants

+ {% if user_can_proofread_source %} +
+ {% for field in proofread_filter_form %} +
+ + {% for radio in field %} + + {% endfor %} +
+ {% endfor %} +
+ {% endif %} {% with exists_on_cantus_ultimus=source.exists_on_cantus_ultimus %} From c7306f2d43037749467726a1ffe901ba13baa752 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 11 Nov 2024 17:31:45 +0000 Subject: [PATCH 04/15] feat: add permission check to see if user has proofreading permission for a source --- .../cantusdb_project/main_app/permissions.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/django/cantusdb_project/main_app/permissions.py b/django/cantusdb_project/main_app/permissions.py index 6b48b7253..acf8eb31d 100644 --- a/django/cantusdb_project/main_app/permissions.py +++ b/django/cantusdb_project/main_app/permissions.py @@ -61,6 +61,28 @@ def user_can_proofread_chant(user: User, chant: Chant) -> bool: return user_is_project_manager or (user_is_editor and user_is_assigned_to_source) +def user_can_proofread_source(user: User, source: Source) -> bool: + """ + Checks if the user can access the proofreading page of a given Source. + Used in SourceBrowseChantsView. + """ + if user.is_superuser: + return True + + if user.is_anonymous: + return False + + source_id = source.id + user_is_assigned_to_source: bool = user.sources_user_can_edit.filter( + id=source_id + ).exists() + + user_is_project_manager: bool = user.groups.filter(name="project manager").exists() + user_is_editor: bool = user.groups.filter(name="editor").exists() + + return user_is_project_manager or (user_is_editor and user_is_assigned_to_source) + + def user_can_view_source(user: User, source: Source) -> bool: """ Checks if the user can view an unpublished Source on the site. From 6985fbbd58610b822b759c86f006ff6651f7b4c2 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 11 Nov 2024 17:33:58 +0000 Subject: [PATCH 05/15] feat: add javascript for proofreading filters - Handling of manuscript full text, volpiano, and proofreading filters --- .../cantusdb_project/static/js/chant_list.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/django/cantusdb_project/static/js/chant_list.js b/django/cantusdb_project/static/js/chant_list.js index 813cfb4e6..7b9cce564 100644 --- a/django/cantusdb_project/static/js/chant_list.js +++ b/django/cantusdb_project/static/js/chant_list.js @@ -6,6 +6,11 @@ window.addEventListener("load", function () { const genreFilter = document.getElementById("genreFilter"); const folioFilter = document.getElementById("folioFilter"); + // Proofreading filters (radio buttons) + const manuscriptFullTextStdProofread = document.querySelectorAll('input[name="manuscript_full_text_std_proofread"]'); + const manuscriptFullTextProofread = document.querySelectorAll('input[name="manuscript_full_text_proofread"]'); + const volpianoProofread = document.querySelectorAll('input[name="volpiano_proofread"]'); + // Make sure the select components keep their values across multiple GET requests // so the user can "drill down" on what they want const urlParams = new URLSearchParams(window.location.search); @@ -23,6 +28,18 @@ window.addEventListener("load", function () { folioFilter.value = urlParams.get("folio"); } + // Set the initial state of proofreading filters based on URL parameters + if (urlParams.has("manuscript_full_text_std_proofread")) { + document.querySelector(`input[name="manuscript_full_text_std_proofread"][value="${urlParams.get("manuscript_full_text_std_proofread")}"]`).checked = true; + } + if (urlParams.has("manuscript_full_text_proofread")) { + document.querySelector(`input[name="manuscript_full_text_proofread"][value="${urlParams.get("manuscript_full_text_proofread")}"]`).checked = true; + } + if (urlParams.has("volpiano_proofread")) { + document.querySelector(`input[name="volpiano_proofread"][value="${urlParams.get("volpiano_proofread")}"]`).checked = true; + } + + // Event listeners for the select fields and search input searchText.addEventListener("change", setSearch); sourceFilter.addEventListener("change", setSource); feastFilter.addEventListener("change", setFeastLeft); @@ -30,11 +47,23 @@ window.addEventListener("load", function () { genreFilter.addEventListener("change", setGenre); folioFilter.addEventListener("change", setFolio); + // Event listeners for the proofreading radio buttons + manuscriptFullTextStdProofread.forEach(radio => { + radio.addEventListener("change", setProofreadingFilter); + }); + manuscriptFullTextProofread.forEach(radio => { + radio.addEventListener("change", setProofreadingFilter); + }); + volpianoProofread.forEach(radio => { + radio.addEventListener("change", setProofreadingFilter); + }); + // functions for the auto-jump of various selectors and input fields on the page // the folio selector and folio-feast selector on the right half do source-wide filtering // the feast selector, genre selector, and text search on the left half do folio-wide filtering var url = new URL(window.location.href); + // Handle text search change function setSearch() { const searchTerm = searchText.value; url.searchParams.set('search_text', searchTerm); @@ -86,4 +115,25 @@ window.addEventListener("load", function () { url.searchParams.set('folio', folio); window.location.assign(url); } + + // Helper function to update URL parameters + function updateURLParam(name, value) { + if (value === "") { + url.searchParams.delete(name); + } else { + url.searchParams.set(name, value); + } + } + + // Handle proofreading filters (radio buttons) + function setProofreadingFilter() { + const stdProofread = document.querySelector('input[name="manuscript_full_text_std_proofread"]:checked')?.value; + const proofread = document.querySelector('input[name="manuscript_full_text_proofread"]:checked')?.value; + const volpianoProof = document.querySelector('input[name="volpiano_proofread"]:checked')?.value; + + updateURLParam('manuscript_full_text_std_proofread', stdProofread); + updateURLParam('manuscript_full_text_proofread', proofread); + updateURLParam('volpiano_proofread', volpianoProof); + window.location.assign(url); + } }); From d9465dc204abd985c9ac0347414363e113603fd6 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 11 Nov 2024 17:45:40 +0000 Subject: [PATCH 06/15] docs: update docstring for SourceBrowseChantsView - add proofread filters --- django/cantusdb_project/main_app/views/source.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/django/cantusdb_project/main_app/views/source.py b/django/cantusdb_project/main_app/views/source.py index b9904b7f2..cff677c1f 100644 --- a/django/cantusdb_project/main_app/views/source.py +++ b/django/cantusdb_project/main_app/views/source.py @@ -59,7 +59,10 @@ class SourceBrowseChantsView(ListView): ``search_text``: Filters by text of Chant ``genre``: Filters by genre of Chant ``folio``: Filters by folio of Chant - ``manuscript_full_text_proofread``: Filters if + ``manuscript_full_text_proofread``: Filters by chants that have their full text proofread + ``manuscript_full_text_std_proofread``: Filters by chants that have their standardized + spelling full text proofread + ``volpiano_proofread``: Filters by chants that have their volpiano proofread """ model = Chant From 8fe2fd5e5369839cd9e2b7a8002548c4507f4fbf Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 12 Nov 2024 14:56:56 +0000 Subject: [PATCH 07/15] refactor: fix labels for proofread form --- django/cantusdb_project/main_app/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django/cantusdb_project/main_app/forms.py b/django/cantusdb_project/main_app/forms.py index b22b87114..322a70870 100644 --- a/django/cantusdb_project/main_app/forms.py +++ b/django/cantusdb_project/main_app/forms.py @@ -537,14 +537,14 @@ class SourceBrowseChantsProofreadForm(forms.Form): required=False, ) manuscript_full_text_proofread = forms.ChoiceField( - label="Full text as in Source (source spelling)", + label="Full text as in Source (source spelling) proofread", choices=PROOFREAD_CHOICES, widget=forms.RadioSelect, required=False, ) volpiano_proofread = forms.ChoiceField( - label="Volpiano Proofread", + label="Volpiano proofread", choices=PROOFREAD_CHOICES, widget=forms.RadioSelect, required=False, From 7166909a56482f0f7361336f5f9d7b7c83a1f6e5 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 22 Nov 2024 15:21:12 +0000 Subject: [PATCH 08/15] test: add tests for proofread filters on source browse chants page --- .../main_app/tests/make_fakes.py | 12 ++- .../main_app/tests/test_views/test_source.py | 76 +++++++++++++++++++ 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/django/cantusdb_project/main_app/tests/make_fakes.py b/django/cantusdb_project/main_app/tests/make_fakes.py index c47ae5f30..745ca3472 100644 --- a/django/cantusdb_project/main_app/tests/make_fakes.py +++ b/django/cantusdb_project/main_app/tests/make_fakes.py @@ -149,7 +149,9 @@ def make_fake_chant( manuscript_full_text_std_spelling=None, manuscript_full_text_std_proofread=None, manuscript_full_text=None, + manuscript_full_text_proofread=None, volpiano=None, + volpiano_proofread=None, manuscript_syllabized_full_text=None, next_chant=None, differentia=None, @@ -183,11 +185,15 @@ def make_fake_chant( if manuscript_full_text_std_spelling is None: manuscript_full_text_std_spelling = faker.sentence() if manuscript_full_text_std_proofread is None: - manuscript_full_text_std_proofread = False + manuscript_full_text_std_proofread = random.choice([True, False, None]) if manuscript_full_text is None: manuscript_full_text = manuscript_full_text_std_spelling + if manuscript_full_text_proofread is None: + manuscript_full_text_proofread = random.choice([True, False, None]) if volpiano is None: volpiano = make_fake_volpiano() + if volpiano_proofread is None: + volpiano_proofread = random.choice([True, False, None]) if manuscript_syllabized_full_text is None: manuscript_syllabized_full_text = faker.sentence(20) if differentia is None: @@ -220,9 +226,9 @@ def make_fake_chant( manuscript_full_text_std_spelling=manuscript_full_text_std_spelling, manuscript_full_text_std_proofread=manuscript_full_text_std_proofread, manuscript_full_text=manuscript_full_text, - manuscript_full_text_proofread=faker.boolean(), + manuscript_full_text_proofread=manuscript_full_text_proofread, volpiano=volpiano, - volpiano_proofread=faker.boolean(), + volpiano_proofread=volpiano_proofread, image_link=image_link, cao_concordances=make_random_string(12, "ABCDEFGHIJKLMNOPQRSTUVWXYZ "), melody_id="m" + make_random_string(8, "0123456789."), diff --git a/django/cantusdb_project/main_app/tests/test_views/test_source.py b/django/cantusdb_project/main_app/tests/test_views/test_source.py index e316495a9..d8f250f3c 100644 --- a/django/cantusdb_project/main_app/tests/test_views/test_source.py +++ b/django/cantusdb_project/main_app/tests/test_views/test_source.py @@ -609,6 +609,82 @@ def test_search_full_text_std_spelling(self): ) self.assertIn(chant, response.context["chants"]) + def test_search_proofread(self): + cantus_segment = make_fake_segment(id=4063) + source = make_fake_source(segment=cantus_segment) + chant_std_proofread = make_fake_chant( + source=source, + manuscript_full_text_std_proofread=True, + manuscript_full_text_proofread=False, + volpiano_proofread=False, + ) + chant_ft_proofread = make_fake_chant( + source=source, + manuscript_full_text_std_proofread=False, + manuscript_full_text_proofread=True, + volpiano_proofread=False, + ) + chant_volpiano_proofread = make_fake_chant( + source=source, + manuscript_full_text_std_proofread=False, + manuscript_full_text_proofread=False, + volpiano_proofread=True, + ) + response = self.client.get( + reverse("browse-chants", args=[source.id]), + ) + self.assertIn(chant_std_proofread, response.context["chants"]) + self.assertIn(chant_ft_proofread, response.context["chants"]) + self.assertIn(chant_volpiano_proofread, response.context["chants"]) + + response = self.client.get( + reverse("browse-chants", args=[source.id]), + {"manuscript_full_text_std_proofread": True}, + ) + self.assertIn(chant_std_proofread, response.context["chants"]) + self.assertNotIn(chant_ft_proofread, response.context["chants"]) + self.assertNotIn(chant_volpiano_proofread, response.context["chants"]) + + response = self.client.get( + reverse("browse-chants", args=[source.id]), + {"manuscript_full_text_std_proofread": False}, + ) + self.assertNotIn(chant_std_proofread, response.context["chants"]) + self.assertIn(chant_ft_proofread, response.context["chants"]) + self.assertIn(chant_volpiano_proofread, response.context["chants"]) + + response = self.client.get( + reverse("browse-chants", args=[source.id]), + {"manuscript_full_text_proofread": True}, + ) + self.assertNotIn(chant_std_proofread, response.context["chants"]) + self.assertIn(chant_ft_proofread, response.context["chants"]) + self.assertNotIn(chant_volpiano_proofread, response.context["chants"]) + + response = self.client.get( + reverse("browse-chants", args=[source.id]), + {"manuscript_full_text_proofread": False}, + ) + self.assertIn(chant_std_proofread, response.context["chants"]) + self.assertNotIn(chant_ft_proofread, response.context["chants"]) + self.assertIn(chant_volpiano_proofread, response.context["chants"]) + + response = self.client.get( + reverse("browse-chants", args=[source.id]), + {"volpiano_proofread": True}, + ) + self.assertNotIn(chant_std_proofread, response.context["chants"]) + self.assertNotIn(chant_ft_proofread, response.context["chants"]) + self.assertIn(chant_volpiano_proofread, response.context["chants"]) + + response = self.client.get( + reverse("browse-chants", args=[source.id]), + {"volpiano_proofread": False}, + ) + self.assertIn(chant_std_proofread, response.context["chants"]) + self.assertIn(chant_ft_proofread, response.context["chants"]) + self.assertNotIn(chant_volpiano_proofread, response.context["chants"]) + def test_context_source(self): cantus_segment = make_fake_segment(id=4063) source = make_fake_source(segment=cantus_segment) From 27a8abb1619e524301fc561ffa84b8750d34dc42 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 22 Nov 2024 15:21:37 +0000 Subject: [PATCH 09/15] fix: fix proofread filter bug in SourceBrowseChantsView --- django/cantusdb_project/main_app/views/source.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/django/cantusdb_project/main_app/views/source.py b/django/cantusdb_project/main_app/views/source.py index cff677c1f..5f0e3b019 100644 --- a/django/cantusdb_project/main_app/views/source.py +++ b/django/cantusdb_project/main_app/views/source.py @@ -119,13 +119,13 @@ def get_queryset(self): | Q(manuscript_full_text__icontains=search_text) ) # Apply proofreading filters if they are set - if manuscript_full_text_proofread: + if manuscript_full_text_std_proofread: chants = chants.filter( - manuscript_full_text_std_proofread=manuscript_full_text_proofread + manuscript_full_text_std_proofread=manuscript_full_text_std_proofread ) - if manuscript_full_text_std_proofread: + if manuscript_full_text_proofread: chants = chants.filter( - manuscript_full_text_proofread=manuscript_full_text_std_proofread + manuscript_full_text_proofread=manuscript_full_text_proofread ) if volpiano_proofread: chants = chants.filter(volpiano_proofread=volpiano_proofread) From 1a3c6a69bc529f1435ae703400f2c5b05c28843b Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 22 Nov 2024 15:27:20 +0000 Subject: [PATCH 10/15] test(chant): use boolean value on proofread fields --- django/cantusdb_project/main_app/tests/make_fakes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/django/cantusdb_project/main_app/tests/make_fakes.py b/django/cantusdb_project/main_app/tests/make_fakes.py index 745ca3472..814400f69 100644 --- a/django/cantusdb_project/main_app/tests/make_fakes.py +++ b/django/cantusdb_project/main_app/tests/make_fakes.py @@ -185,15 +185,15 @@ def make_fake_chant( if manuscript_full_text_std_spelling is None: manuscript_full_text_std_spelling = faker.sentence() if manuscript_full_text_std_proofread is None: - manuscript_full_text_std_proofread = random.choice([True, False, None]) + manuscript_full_text_std_proofread = faker.boolean() if manuscript_full_text is None: manuscript_full_text = manuscript_full_text_std_spelling if manuscript_full_text_proofread is None: - manuscript_full_text_proofread = random.choice([True, False, None]) + manuscript_full_text_proofread = faker.boolean() if volpiano is None: volpiano = make_fake_volpiano() if volpiano_proofread is None: - volpiano_proofread = random.choice([True, False, None]) + volpiano_proofread = faker.boolean() if manuscript_syllabized_full_text is None: manuscript_syllabized_full_text = faker.sentence(20) if differentia is None: From b793858b205df64b7bb319ffa0ee1304b909fe4f Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 22 Nov 2024 15:39:00 +0000 Subject: [PATCH 11/15] test: fix occasionally failing test in SourceEditChantsViewTest --- .../cantusdb_project/main_app/tests/test_views/test_chant.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/django/cantusdb_project/main_app/tests/test_views/test_chant.py b/django/cantusdb_project/main_app/tests/test_views/test_chant.py index 9692c8e36..1a979ad0d 100644 --- a/django/cantusdb_project/main_app/tests/test_views/test_chant.py +++ b/django/cantusdb_project/main_app/tests/test_views/test_chant.py @@ -303,7 +303,9 @@ def test_chant_with_volpiano_with_no_incipit(self): def test_proofread_chant(self): chant = make_fake_chant( - manuscript_full_text_std_spelling="lorem ipsum", folio="001r" + manuscript_full_text_std_spelling="lorem ipsum", + folio="001r", + manuscript_full_text_std_proofread=False, ) folio = chant.folio c_sequence = chant.c_sequence From a8581ef76365dde8563f2886201e1dba91f62d61 Mon Sep 17 00:00:00 2001 From: Lucas <71031342+lucasmarchd01@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:25:03 -0500 Subject: [PATCH 12/15] fix: fix typing Co-authored-by: Dylan Hillerbrand --- django/cantusdb_project/main_app/views/source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/cantusdb_project/main_app/views/source.py b/django/cantusdb_project/main_app/views/source.py index 5f0e3b019..1248e60a8 100644 --- a/django/cantusdb_project/main_app/views/source.py +++ b/django/cantusdb_project/main_app/views/source.py @@ -103,7 +103,7 @@ def get_queryset(self): volpiano_proofread = self.request.GET.get("volpiano_proofread") # get all chants in the specified source - chants: QuerySet = source.chant_set.select_related("feast", "service", "genre") + chants: QuerySet[Chant] = source.chant_set.select_related("feast", "service", "genre") # filter the chants with optional search params if feast_id: chants = chants.filter(feast__id=feast_id) From 94cc2bc3af931ce5a0a729b4947446c0de11ca85 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 2 Dec 2024 17:39:16 +0000 Subject: [PATCH 13/15] style: add spacing between radio select buttons --- .../main_app/templates/browse_chants.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/django/cantusdb_project/main_app/templates/browse_chants.html b/django/cantusdb_project/main_app/templates/browse_chants.html index 1b80a0b58..d8d63bb19 100644 --- a/django/cantusdb_project/main_app/templates/browse_chants.html +++ b/django/cantusdb_project/main_app/templates/browse_chants.html @@ -62,13 +62,13 @@

Browse Chants

{% for field in proofread_filter_form %}
- - {% for radio in field %} - - {% endfor %} + + {% for radio in field %} + + {% endfor %}
{% endfor %}
From 78c402edd07daa3866e2cefa93ab2c9cd5ff4ffd Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 2 Dec 2024 17:39:41 +0000 Subject: [PATCH 14/15] refactor: add permission check for user_can_proofread_chant --- django/cantusdb_project/main_app/permissions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django/cantusdb_project/main_app/permissions.py b/django/cantusdb_project/main_app/permissions.py index acf8eb31d..bd36e909e 100644 --- a/django/cantusdb_project/main_app/permissions.py +++ b/django/cantusdb_project/main_app/permissions.py @@ -51,6 +51,8 @@ def user_can_proofread_chant(user: User, chant: Chant) -> bool: return False source_id = chant.source.id + user_can_proofread_src = user_can_proofread_source(user, chant.source) + user_is_assigned_to_source: bool = user.sources_user_can_edit.filter( # noqa id=source_id ).exists() @@ -58,7 +60,9 @@ def user_can_proofread_chant(user: User, chant: Chant) -> bool: user_is_project_manager: bool = user.groups.filter(name="project manager").exists() user_is_editor: bool = user.groups.filter(name="editor").exists() - return user_is_project_manager or (user_is_editor and user_is_assigned_to_source) + return user_can_proofread_src and ( + user_is_project_manager or (user_is_editor and user_is_assigned_to_source) + ) def user_can_proofread_source(user: User, source: Source) -> bool: From 41f5ba78d5fbe3f1e285c3c85e8368def4b365dc Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 2 Dec 2024 17:46:55 +0000 Subject: [PATCH 15/15] style: black formatting --- django/cantusdb_project/main_app/views/source.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/django/cantusdb_project/main_app/views/source.py b/django/cantusdb_project/main_app/views/source.py index 76d673695..ab26959e1 100644 --- a/django/cantusdb_project/main_app/views/source.py +++ b/django/cantusdb_project/main_app/views/source.py @@ -103,7 +103,9 @@ def get_queryset(self): volpiano_proofread = self.request.GET.get("volpiano_proofread") # get all chants in the specified source - chants: QuerySet[Chant] = source.chant_set.select_related("feast", "service", "genre") + chants: QuerySet[Chant] = source.chant_set.select_related( + "feast", "service", "genre" + ) # filter the chants with optional search params if feast_id: chants = chants.filter(feast__id=feast_id)