Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust sortable columns for source list page (based on email feedback) #1618

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions django/cantusdb_project/main_app/templates/source_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ <h3>Browse Sources</h3>
<thead>
<tr>
{% sortable_header request "country" %}
{% sortable_header request "heading" "Source" %}
{% sortable_header request "city_institution" "City + Institution" %}
{% sortable_header request "source" "Source" %}
<th scope="col" class="text-wrap" style="text-align:center">Summary</th>
<th scope="col" class="text-wrap" style="text-align:center">Date/Origin</th>
<th scope="col" class="text-wrap" style="text-align:center">Image Link</th>
Expand All @@ -101,9 +102,14 @@ <h3>Browse Sources</h3>
<td class="text-wrap" style="text-align:center">
<b>{{ source.holding_institution.country }}</b>
</td>
<td class="text-wrap" style="text-align:center" title="{{ source.heading }}">
<td class="text-wrap" style="text-align:center">
<a href="{% url 'source-detail' source.id %}">
<b>{{ source.holding_institution.city }}, {{ source.holding_institution.name }}</b>
</a>
</td>
<td class="text-wrap" style="text-align:center">
<a href="{% url 'source-detail' source.id %}">
<b>{{ source.heading|truncatechars_html:100 }}</b>
<b>{{ source.short_heading|truncatechars_html:100 }}</b>
</a>
</td>
<td class="text-wrap" style="text-align:center" title="{{ source.summary|default:""|truncatechars_html:500 }}">
Expand Down
73 changes: 73 additions & 0 deletions django/cantusdb_project/main_app/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4694,6 +4694,79 @@ def test_search_by_indexing_notes(self):
response = self.client.get(reverse("source-list"), {"general": search_term})
self.assertIn(source, response.context["sources"])

def test_ordering(self) -> None:
"""
Order is currently available by country, city + institution name (parameter:
"city_institution"), and siglum + shelfmark. Siglum + shelfmark is the default.
"""
# Create a bunch of sources
sources = []
for _ in range(10):
sources.append(make_fake_source())
# Default ordering is by siglum and shelfmark, ascending
with self.subTest("Default ordering"):
response = self.client.get(reverse("source-list"))
response_sources = response.context["sources"]
expected_source_order = sorted(
sources,
key=lambda source: (
source.holding_institution.siglum,
source.shelfmark,
),
)
self.assertEqual(
list(expected_source_order),
list(response_sources),
)
response_reverse = self.client.get(reverse("source-list"), {"sort": "desc"})
response_sources_reverse = response_reverse.context["sources"]
self.assertEqual(
list(reversed(expected_source_order)),
list(response_sources_reverse),
)
with self.subTest("Order by country, ascending"):
response = self.client.get(reverse("source-list"), {"order": "country"})
response_sources = response.context["sources"]
expected_source_order = sorted(
sources, key=lambda source: source.holding_institution.country
)
self.assertEqual(
list(expected_source_order),
list(response_sources),
)
response_reverse = self.client.get(
reverse("source-list"), {"order": "country", "sort": "desc"}
)
response_sources_reverse = response_reverse.context["sources"]
self.assertEqual(
list(reversed(expected_source_order)),
list(response_sources_reverse),
)
with self.subTest("Order by city and institution name, ascending"):
response = self.client.get(
reverse("source-list"), {"order": "city_institution"}
)
response_sources = response.context["sources"]
expected_source_order = sorted(
sources,
key=lambda source: (
source.holding_institution.city,
source.holding_institution.name,
),
)
self.assertEqual(
list(expected_source_order),
list(response_sources),
)
response_reverse = self.client.get(
reverse("source-list"), {"order": "city_institution", "sort": "desc"}
)
response_sources_reverse = response_reverse.context["sources"]
self.assertEqual(
list(reversed(expected_source_order)),
list(response_sources_reverse),
)


class SourceCreateViewTest(TestCase):
@classmethod
Expand Down
4 changes: 2 additions & 2 deletions django/cantusdb_project/main_app/views/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ def get_queryset(self) -> QuerySet[Source]:
q_obj_filter &= indexing_search_q

order_param = self.request.GET.get("order")
order_fields = ["siglum"]
order_fields = ["holding_institution__siglum", "shelfmark"]
if order_param == "country":
order_fields.insert(0, "holding_institution__country")
if order_param == "heading":
elif order_param == "city_institution":
order_fields.insert(0, "holding_institution__city")
order_fields.insert(1, "holding_institution__name")
if self.request.GET.get("sort") == "desc":
Expand Down
Loading