Skip to content

Commit

Permalink
Merge remote-tracking branch 'jacobdgm/1376-browse-chants-unpublished…
Browse files Browse the repository at this point in the history
…' into develop
  • Loading branch information
dchiller committed Mar 21, 2024
2 parents 9057bdd + 6d0f590 commit 491968b
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ <h4><a href="{% url 'source-detail' source.id %}" title="{{ source.title }}">{{
</select>

{% if previous_folio %}
<a href="{% url "chant-list" source.id %}?folio={{ previous_folio }}">{{ previous_folio }} <</a>
<a href="{% url "browse-chants" source.id %}?folio={{ previous_folio }}">{{ previous_folio }} <</a>
{% endif %}
{% if next_folio %}
&nbsp;<a href="{% url "chant-list" source.id %}?folio={{ next_folio }}">> {{ next_folio }}</a>
&nbsp;<a href="{% url "browse-chants" source.id %}?folio={{ next_folio }}">> {{ next_folio }}</a>
{% endif %}
<br>

Expand All @@ -163,7 +163,7 @@ <h4><a href="{% url 'source-detail' source.id %}" title="{{ source.title }}">{{
{% endfor %}
</select>
<br>
<a href="{% url "chant-list" source.id %}" class="guillemet" target="_blank">View all chants</a>
<a href="{% url "browse-chants" source.id %}" class="guillemet" target="_blank">View all chants</a>
<a href="{% url "source-inventory" source.id %}" class="guillemet" target="_blank">View full inventory</a>
<a href="{% url "csv-export" source.id%}" class="guillemet" target="_blank">CSV export</a>
<a href="{% url "chant-search-ms" source.id %}" class="guillemet" target="_blank">Search chants in this manuscript</a>
Expand Down
4 changes: 2 additions & 2 deletions django/cantusdb_project/main_app/templates/chant_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ <h4>List of melodies</h4>
</select>

{% if previous_folio %}
<a href="{% url "chant-list" source.id %}?folio={{ previous_folio }}">{{ previous_folio }} <</a>
<a href="{% url "browse-chants" source.id %}?folio={{ previous_folio }}">{{ previous_folio }} <</a>
{% endif %}
{% if next_folio %}
&nbsp;<a href="{% url "chant-list" source.id %}?folio={{ next_folio }}">> {{ next_folio }}</a>
&nbsp;<a href="{% url "browse-chants" source.id %}?folio={{ next_folio }}">> {{ next_folio }}</a>
{% endif %}

{% if chant.image_link %}
Expand Down
4 changes: 2 additions & 2 deletions django/cantusdb_project/main_app/templates/feast_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ <h4>Sources containing the feast</h4>
<tbody>
{% for source, count in sources_zip %}
<tr>
<td><a href="{% url 'chant-list' source.id %}" title="{{ source.title }}">{{ source.siglum }}</a></td>
<td><a href="{% url 'chant-list' source.id %}?feast={{ feast.id }}">{{ count }}</a></td>
<td><a href="{% url 'browse-chants' source.id %}" title="{{ source.title }}">{{ source.siglum }}</a></td>
<td><a href="{% url 'browse-chants' source.id %}?feast={{ feast.id }}">{{ count }}</a></td>
</tr>
{% endfor %}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ <h4>{{ source.siglum }}</h4>
</select>

<br>
<a href="{% url "chant-list" source.id %}" class="guillemet" target="_blank">View all chants</a>
<a href="{% url "browse-chants" source.id %}" class="guillemet" target="_blank">View all chants</a>
{% endif %}
<a href="{% url "source-inventory" source.id %}" class="guillemet" target="_blank">View full inventory</a>
<a href="{% url "csv-export" source.id%}" class="guillemet" target="_blank" download="{{ source.id }}.csv">CSV export</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ <h4>{{ source.siglum }}</h4>
<br>
{% if source.segment.id == 4063 %}
{# only display this link for sources in the CANTUS segment #}
<a href="{% url "chant-list" source.id %}" class="guillemet" target="_blank">View all chants</a>
<a href="{% url "browse-chants" source.id %}" class="guillemet" target="_blank">View all chants</a>
{% endif %}
<a href="{% url "source-inventory" source.id %}" class="guillemet" target="_blank">View full inventory</a>
<a href="{% url "csv-export" source.id%}" class="guillemet" target="_blank" download="{{ source.id }}.csv">CSV export</a>
Expand Down
46 changes: 24 additions & 22 deletions django/cantusdb_project/main_app/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,40 +539,42 @@ def test_unpublished_sources_not_listed(self):
self.assertNotIn(source, returned_sources)


class ChantListViewTest(TestCase):
class SourceBrowseChantsViewTest(TestCase):
def test_url_and_templates(self):
cantus_segment = make_fake_segment(id=4063)
source = make_fake_source(segment=cantus_segment)
response = self.client.get(reverse("chant-list", args=[source.id]))
response = self.client.get(reverse("browse-chants", args=[source.id]))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "base.html")
self.assertTemplateUsed(response, "chant_list.html")
self.assertTemplateUsed(response, "browse_chants.html")

def test_published_vs_unpublished(self):
cantus_segment = make_fake_segment(id=4063)

published_source = make_fake_source(segment=cantus_segment, published=True)
response_1 = self.client.get(reverse("chant-list", args=[published_source.id]))
response_1 = self.client.get(
reverse("browse-chants", args=[published_source.id])
)
self.assertEqual(response_1.status_code, 200)

unpublished_source = make_fake_source(segment=cantus_segment, published=False)
response_2 = self.client.get(
reverse("chant-list", args=[unpublished_source.id])
reverse("browse-chants", args=[unpublished_source.id])
)
self.assertEqual(response_2.status_code, 403)

def test_visibility_by_segment(self):
cantus_segment = make_fake_segment(id=4063)
cantus_source = make_fake_source(segment=cantus_segment, published=True)
response_1 = self.client.get(reverse("chant-list", args=[cantus_source.id]))
response_1 = self.client.get(reverse("browse-chants", args=[cantus_source.id]))
self.assertEqual(response_1.status_code, 200)

# The chant list ("Browse Chants") page should only be visitable
# for sources in the CANTUS Database segment, as sources in the Bower
# segment contain no chants
bower_segment = make_fake_segment(id=4064)
bower_source = make_fake_source(segment=bower_segment, published=True)
response_1 = self.client.get(reverse("chant-list", args=[bower_source.id]))
response_1 = self.client.get(reverse("browse-chants", args=[bower_source.id]))
self.assertEqual(response_1.status_code, 404)

def test_filter_by_source(self):
Expand All @@ -581,7 +583,7 @@ def test_filter_by_source(self):
another_source = make_fake_source(segment=cantus_segment)
chant_in_source = Chant.objects.create(source=source)
chant_in_another_source = Chant.objects.create(source=another_source)
response = self.client.get(reverse("chant-list", args=[source.id]))
response = self.client.get(reverse("browse-chants", args=[source.id]))
chants = response.context["chants"]
self.assertIn(chant_in_source, chants)
self.assertNotIn(chant_in_another_source, chants)
Expand All @@ -596,7 +598,7 @@ def test_filter_by_feast(self):
source=source, feast=another_feast
)
response = self.client.get(
reverse("chant-list", args=[source.id]), {"feast": feast.id}
reverse("browse-chants", args=[source.id]), {"feast": feast.id}
)
chants = response.context["chants"]
self.assertIn(chant_in_feast, chants)
Expand All @@ -612,7 +614,7 @@ def test_filter_by_genre(self):
source=source, genre=another_genre
)
response = self.client.get(
reverse("chant-list", args=[source.id]), {"genre": genre.id}
reverse("browse-chants", args=[source.id]), {"genre": genre.id}
)
chants = response.context["chants"]
self.assertIn(chant_in_genre, chants)
Expand All @@ -624,7 +626,7 @@ def test_filter_by_folio(self):
chant_on_folio = Chant.objects.create(source=source, folio="001r")
chant_on_another_folio = Chant.objects.create(source=source, folio="002r")
response = self.client.get(
reverse("chant-list", args=[source.id]), {"folio": "001r"}
reverse("browse-chants", args=[source.id]), {"folio": "001r"}
)
chants = response.context["chants"]
self.assertIn(chant_on_folio, chants)
Expand All @@ -638,7 +640,7 @@ def test_search_full_text(self):
)
search_term = get_random_search_term(chant.manuscript_full_text)
response = self.client.get(
reverse("chant-list", args=[source.id]), {"search_text": search_term}
reverse("browse-chants", args=[source.id]), {"search_text": search_term}
)
self.assertIn(chant, response.context["chants"])

Expand All @@ -651,7 +653,7 @@ def test_search_incipit(self):
)
search_term = get_random_search_term(chant.incipit)
response = self.client.get(
reverse("chant-list", args=[source.id]), {"search_text": search_term}
reverse("browse-chants", args=[source.id]), {"search_text": search_term}
)
self.assertIn(chant, response.context["chants"])

Expand All @@ -664,14 +666,14 @@ def test_search_full_text_std_spelling(self):
)
search_term = get_random_search_term(chant.manuscript_full_text_std_spelling)
response = self.client.get(
reverse("chant-list", args=[source.id]), {"search_text": search_term}
reverse("browse-chants", args=[source.id]), {"search_text": search_term}
)
self.assertIn(chant, response.context["chants"])

def test_context_source(self):
cantus_segment = make_fake_segment(id=4063)
source = make_fake_source(segment=cantus_segment)
response = self.client.get(reverse("chant-list", args=[source.id]))
response = self.client.get(reverse("browse-chants", args=[source.id]))
self.assertEqual(source, response.context["source"])

def test_context_folios(self):
Expand All @@ -683,7 +685,7 @@ def test_context_folios(self):
Chant.objects.create(source=source, folio="001v")
Chant.objects.create(source=source, folio="002r")
Chant.objects.create(source=source, folio="002v")
response = self.client.get(reverse("chant-list", args=[source.id]))
response = self.client.get(reverse("browse-chants", args=[source.id]))
# the element in "folios" should be unique and ordered in this way
folios = response.context["folios"]
self.assertEqual(list(folios), ["001r", "001v", "002r", "002v"])
Expand All @@ -699,7 +701,7 @@ def test_context_feasts_with_folios(self):
Chant.objects.create(source=source, folio="001v")
Chant.objects.create(source=source, folio="001v", feast=feast_2)
Chant.objects.create(source=source, folio="002r", feast=feast_1)
response = self.client.get(reverse("chant-list", args=[source.id]))
response = self.client.get(reverse("browse-chants", args=[source.id]))
# context "feasts_with_folios" is a list of tuples
# it records the folios where the feast changes
expected_result = [("001r", feast_1), ("001v", feast_2), ("002r", feast_1)]
Expand All @@ -710,14 +712,14 @@ def test_redirect_with_source_parameter(self):
source = make_fake_source(segment=cantus_segment)
source_id = source.id

url = reverse("redirect-chant-list")
url = reverse("redirect-chants")
response = self.client.get(f"{url}?source={source_id}")
self.assertRedirects(
response, reverse("chant-list", args=[source_id]), status_code=301
response, reverse("browse-chants", args=[source_id]), status_code=301
)

def test_redirect_without_source_parameter(self):
url = reverse("redirect-chant-list")
url = reverse("redirect-chants")

# Omitting the source parameter to simulate a bad request
response = self.client.get(url)
Expand Down Expand Up @@ -4269,7 +4271,7 @@ def test_published_vs_unpublished(self):
def test_chant_list_link(self):
cantus_segment = make_fake_segment(id=4063)
cantus_source = make_fake_source(segment=cantus_segment)
chant_list_link = reverse("chant-list", args=[cantus_source.id])
chant_list_link = reverse("browse-chants", args=[cantus_source.id])

cantus_source_response = self.client.get(
reverse("source-detail", args=[cantus_source.id])
Expand All @@ -4279,7 +4281,7 @@ def test_chant_list_link(self):

bower_segment = make_fake_segment(id=4064)
bower_source = make_fake_source(segment=bower_segment)
bower_chant_list_link = reverse("chant-list", args=[bower_source.id])
bower_chant_list_link = reverse("browse-chants", args=[bower_source.id])
bower_source_response = self.client.get(
reverse("source-detail", args=[bower_source.id])
)
Expand Down
10 changes: 5 additions & 5 deletions django/cantusdb_project/main_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
ChantDeleteView,
ChantDetailView,
ChantEditSyllabificationView,
ChantListView,
ChantSearchView,
ChantSearchMSView,
MelodySearchView,
Expand Down Expand Up @@ -46,6 +45,7 @@
SequenceListView,
)
from main_app.views.source import (
SourceBrowseChantsView,
SourceCreateView,
SourceDetailView,
SourceEditView,
Expand Down Expand Up @@ -190,8 +190,8 @@
),
path(
"chants/",
views.redirect_chant_list,
name="redirect-chant-list",
views.redirect_chants,
name="redirect-chants",
), # /chants/?source={source id}
# feast
path(
Expand Down Expand Up @@ -283,8 +283,8 @@
),
path(
"source/<int:source_id>/chants/",
ChantListView.as_view(),
name="chant-list",
SourceBrowseChantsView.as_view(),
name="browse-chants",
),
path(
"source/<int:source_id>/inventory/",
Expand Down
Loading

0 comments on commit 491968b

Please sign in to comment.