diff --git a/django/cantusdb_project/main_app/views/source.py b/django/cantusdb_project/main_app/views/source.py index 510d86f98..4766e163e 100644 --- a/django/cantusdb_project/main_app/views/source.py +++ b/django/cantusdb_project/main_app/views/source.py @@ -210,7 +210,7 @@ def get_context_data(self, **kwargs): return context -class SourceListView(ListView): +class SourceListView(ListView): # type: ignore model = Source paginate_by = 100 context_object_name = "sources" @@ -232,41 +232,39 @@ def get_queryset(self) -> QuerySet[Source]: "segment", "provenance", "holding_institution" ) - display_unpublished: bool = self.request.user.is_authenticated - if display_unpublished: + if self.request.user.is_authenticated: q_obj_filter = Q() else: q_obj_filter = Q(published=True) - if self.request.GET.get("century"): - century_name = Century.objects.get(id=self.request.GET.get("century")).name + if century_id := self.request.GET.get("century"): + century_name = Century.objects.get(id=century_id).name q_obj_filter &= Q(century__name__icontains=century_name) - if self.request.GET.get("provenance"): - provenance_id = int(self.request.GET.get("provenance")) - q_obj_filter &= Q(provenance__id=provenance_id) - if self.request.GET.get("segment"): - segment_id = int(self.request.GET.get("segment")) - q_obj_filter &= Q(segment__id=segment_id) - if self.request.GET.get("fullSource") in ["true", "false"]: - full_source_str = self.request.GET.get("fullSource") + if provenance_id := self.request.GET.get("provenance"): + q_obj_filter &= Q(provenance__id=int(provenance_id)) + if segment_id := self.request.GET.get("segment"): + q_obj_filter &= Q(segment__id=int(segment_id)) + if (full_source_str := self.request.GET.get("fullSource")) in ["true", "false"]: if full_source_str == "true": full_source_q = Q(full_source=True) | Q(full_source=None) q_obj_filter &= full_source_q else: q_obj_filter &= Q(full_source=False) - if self.request.GET.get("general"): + if general_str := self.request.GET.get("general"): # Strip spaces at the beginning and end. Then make list of terms split on spaces - general_search_terms = self.request.GET.get("general").strip(" ").split(" ") + general_search_terms = general_str.strip(" ").split(" ") # We need a Q Object for each field we're gonna look into shelfmark_q = Q() siglum_q = Q() holding_institution_q = Q() holding_institution_city_q = Q() description_q = Q() - # it seems that old cantus don't look into title and provenance for the general search terms - # cantus.uwaterloo.ca/source/123901 this source cannot be found by searching its provenance 'Kremsmünster' in the general search field + # it seems that old cantus don't look into title and provenance + # for the general search terms + # cantus.uwaterloo.ca/source/123901 this source cannot be found by searching + # its provenance 'Kremsmünster' in the general search field # provenance_q = Q() summary_q = Q() @@ -302,9 +300,9 @@ def get_queryset(self) -> QuerySet[Source]: # For the indexing notes search we follow the same procedure as above but with # different fields - if self.request.GET.get("indexing"): + if indexing_str := self.request.GET.get("indexing"): # Make list of terms split on spaces - indexing_search_terms = self.request.GET.get("indexing").split(" ") + indexing_search_terms = indexing_str.strip(" ").split(" ") # We need a Q Object for each field we're gonna look into inventoried_by_q = Q() full_text_entered_by_q = Q()