Skip to content

Commit

Permalink
fix(source list view): use source_completeness field to filter source…
Browse files Browse the repository at this point in the history
… list
  • Loading branch information
dchiller committed Oct 15, 2024
1 parent 9d63616 commit 7561b0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 7 additions & 9 deletions django/cantusdb_project/main_app/tests/test_views/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,44 +846,42 @@ def test_filter_by_century(self):

def test_filter_by_full_source(self):
full_source = make_fake_source(
full_source=True,
source_completeness=Source.SourceCompletenessChoices.FULL_SOURCE,
published=True,
shelfmark="full source",
)
fragment = make_fake_source(
full_source=False,
source_completeness=Source.SourceCompletenessChoices.FRAGMENT,
published=True,
shelfmark="fragment",
)
unknown = make_fake_source(
full_source=None,
reconstruction = make_fake_source(
source_completeness=Source.SourceCompletenessChoices.RECONSTRUCTION,
published=True,
shelfmark="full_source field is empty",
)

# display full sources
response = self.client.get(reverse("source-list"), {"fullSource": "true"})
sources = response.context["sources"]
# full_source and unknown_source should be in the list, fragment should not
self.assertIn(full_source, sources)
self.assertNotIn(fragment, sources)
self.assertIn(unknown, sources)
self.assertNotIn(reconstruction, sources)

# display fragments
response = self.client.get(reverse("source-list"), {"fullSource": "false"})
sources = response.context["sources"]
# fragment should be in the list, full_source and unknown_source should not
self.assertNotIn(full_source, sources)
self.assertIn(fragment, sources)
self.assertNotIn(unknown, sources)
self.assertNotIn(reconstruction, sources)

# display all sources
response = self.client.get(reverse("source-list"))
sources = response.context["sources"]
# all three should be in the list
self.assertIn(full_source, sources)
self.assertIn(fragment, sources)
self.assertIn(unknown, sources)
self.assertIn(reconstruction, sources)

def test_search_by_title(self):
"""The "general search" field searches in `title`, `shelfmark`, `description`, and `summary`"""
Expand Down
9 changes: 6 additions & 3 deletions django/cantusdb_project/main_app/views/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,13 @@ def get_queryset(self) -> QuerySet[Source]:
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
q_obj_filter &= Q(
source_completeness=Source.SourceCompletenessChoices.FULL_SOURCE
)
else:
q_obj_filter &= Q(full_source=False)
q_obj_filter &= Q(
source_completeness=Source.SourceCompletenessChoices.FRAGMENT
)

if general_str := self.request.GET.get("general"):
# Strip spaces at the beginning and end. Then make list of terms split on spaces
Expand Down

0 comments on commit 7561b0e

Please sign in to comment.