Skip to content

Commit

Permalink
Merge pull request #1463 from DDMAL/develop
Browse files Browse the repository at this point in the history
Merge develop into staging, 16 May 2024
  • Loading branch information
lucasmarchd01 authored May 16, 2024
2 parents 7ec5a66 + 80231fd commit 94cde34
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from django.core.management.base import BaseCommand
from main_app.models import Source, Chant, Segment

CHANT_CHUNK_SIZE = 1_000


class Command(BaseCommand):
help = "Assigns all chants in the database to the segment of the source they belong to."
Expand All @@ -20,11 +18,4 @@ def handle(self, *args, **options):
for source in sources:
segment = Segment.objects.get(id=source.segment_id)
chants = Chant.objects.filter(source=source)
chants_count = chants.count()
start_index = 0
while start_index < chants_count:
chant_chunk = chants[start_index : start_index + CHANT_CHUNK_SIZE]
for chant in chant_chunk:
chant.segment = segment
chant.save()
start_index += CHANT_CHUNK_SIZE
chants.update(segment=segment)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from main_app.models import Source
from django.core.management.base import BaseCommand
import requests
from requests import Response

# This management command updates the exists_on_cantus_ultimus field on a single
# Source or all sources. If a source argument is provided, it will check if the
# Source exists on Cantus Ultimus and update exists_on_cantus_ultimus to True if it
# does.

# If no Source argument is provided, it will update all Cantus Segment Sources in
# the database.

# run with `python manage.py add_cantus_ultimus_links <source_id>`


class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
"source_id",
nargs="?",
type=int,
default=None,
help="This command updates the exists_on_cantus_ultimus field for the Source with the specified ID",
)

def handle(self, *args, **kwargs):
source_id: int = kwargs["source_id"]
if source_id: # update exists_on_cantus_ultimus for a specified source
try:
source: Source = Source.objects.get(id=source_id)
self.update_exists_on_cantus_ultimus(source)
except Source.DoesNotExist:
self.stdout.write(
self.style.ERROR(f"Source {source_id} does not exist")
)
return
else: # No source argument provided, update all sources
sources = Source.objects.filter(segment=4063)
for source in sources:
self.update_exists_on_cantus_ultimus(source)

def update_exists_on_cantus_ultimus(self, source: Source) -> None:
try:
response: Response = requests.get(
f"https://cantus.simssa.ca/manuscript/{source.id}", timeout=10
)
except (TimeoutError, ConnectionError) as e:
self.stdout.write(self.style.ERROR(f"{e} for source: {source.id}"))
# We expect a 404 response if the source doesn't exist on Cantus Ultimus
if response.status_code != 200:
self.stdout.write(
self.style.NOTICE(
f"Source {source.id} may not exist on Cantus Ultimus (Status Code: {response.status_code})\n"
)
)
return
# update the link for the entire source
self.stdout.write(f"\nUpdating exists_on_cantus_ultimus for source: {source}")
source.exists_on_cantus_ultimus = True
source.save()
self.stdout.write(
self.style.SUCCESS(
"Source exists_on_cantus_ultimus updated successfully!\n"
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-05-14 15:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("main_app", "0009_chant_segment_sequence_segment"),
]

operations = [
migrations.AddField(
model_name="source",
name="exists_on_cantus_ultimus",
field=models.BooleanField(default=False),
),
]
3 changes: 3 additions & 0 deletions django/cantusdb_project/main_app/models/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class Source(BaseModel):
dact_id = models.CharField(
max_length=15, blank=True, null=True, verbose_name="DACT ID"
)
exists_on_cantus_ultimus = models.BooleanField(
blank=False, null=False, default=False
)

# number_of_chants and number_of_melodies are used for rendering the source-list page (perhaps among other places)
# they are automatically recalculated in main_app.signals.update_source_chant_count and
Expand Down
154 changes: 81 additions & 73 deletions django/cantusdb_project/main_app/templates/browse_chants.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,79 +52,84 @@ <h3>Browse Chants</h3>
</div>

</form>

{% if chants %}
<table class="table table-responsive table-sm table-bordered small">
<thead>
<tr>
<th scope="col" class="text-wrap" title="Siglum">Siglum</th>
<th scope="col" class="text-wrap" title="Folio">Folio</th>
<th scope="col" class="text-wrap" title="Sequence"></th>
<th scope="col" class="text-wrap" title="Incipit / Full text">Incipit / Full text</th>
<th scope="col" class="text-wrap" title="Feast">Feast</th>
<th scope="col" class="text-wrap" title="Service"></th>
<th scope="col" class="text-wrap" title="Genre"></th>
<th scope="col" class="text-wrap" title="Position"></th>
<th scope="col" class="text-wrap" title="Cantus ID">CantusID</th>
<th scope="col" class="text-wrap" title="Mode">Mode</th>
<th scope="col" class="text-wrap" title="Image link"></th>
{% if user_can_edit_chant %}
<th scope="col" class="text-wrap" title="Edit Chant"></th>
{% endif %}
</tr>
</thead>
<tbody>
{% for chant in chants %}
<tr>
<td class="text-wrap" style="text-align:center" title="{{ chant.source.title }}">{{ chant.source.siglum|default:"" }}</td>
<td class="text-wrap" style="text-align:center"><b>{{ chant.folio|default:"" }}</b></td>
<td class="text-wrap" style="text-align:center">{{ chant.c_sequence|default_if_none:"" }}</td> {# default_if_none: sometimes, c_sequence is 0, and should still be displayed #}
<td class="text-wrap">
<a href="{% url 'chant-detail' chant.id %}"><b>{{ chant.incipit|default:"" }}</b></a>
<p>{{ chant.manuscript_full_text_std_spelling|default:"" }}<br>
{% if chant.volpiano %}
<span style="font-family: volpiano; font-size:25px">{{ chant.volpiano|default:"" }}</span>
{% endif %}
</p>
</td>
<td class="text-wrap" style="text-align:center">
{% if chant.feast %}
<a href="{% url 'feast-detail' chant.feast.id %}" title="{{ chant.feast.description }}">{{ chant.feast.name|default:"" }}</a>
{% endif %}
</td>
<td class="text-wrap" style="text-align:center">
{% if chant.office %}
<a href="{% url 'office-detail' chant.office.id %}" title="{{ chant.office.description }}">{{ chant.office.name|default:"" }}</a>
{% endif %}
</td>
<td class="text-wrap" style="text-align:center">
{% if chant.genre %}
<a href="{% url 'genre-detail' chant.genre.id %}" title="{{ chant.genre.description }}">{{ chant.genre.name|default:"" }}</a>
{% endif %}
</td>
<td class="text-wrap" style="text-align:center">{{ chant.position|default:"" }}</td>
<td class="text-wrap" style="text-align:center">
<a href="{{ chant.get_ci_url }}" target="_blank">{{ chant.cantus_id|default:"" }}</a>
</td>
<td class="text-wrap" style="text-align:center">{{ chant.mode|default:"" }}</td>
<td class="text-wrap" style="text-align:center">
{% if chant.image_link %}
<a href="{{ chant.image_link }}" target="_blank">Image</a>
{% with exists_on_cantus_ultimus=source.exists_on_cantus_ultimus %}
{% if chants %}
<table class="table table-responsive table-sm table-bordered small">
<thead>
<tr>
<th scope="col" class="text-wrap" title="Siglum">Siglum</th>
<th scope="col" class="text-wrap" title="Folio">Folio</th>
<th scope="col" class="text-wrap" title="Sequence"></th>
<th scope="col" class="text-wrap" title="Incipit / Full text">Incipit / Full text</th>
<th scope="col" class="text-wrap" title="Feast">Feast</th>
<th scope="col" class="text-wrap" title="Service"></th>
<th scope="col" class="text-wrap" title="Genre"></th>
<th scope="col" class="text-wrap" title="Position"></th>
<th scope="col" class="text-wrap" title="Cantus ID">CantusID</th>
<th scope="col" class="text-wrap" title="Mode">Mode</th>
<th scope="col" class="text-wrap" title="Image link"></th>
{% if user_can_edit_chant %}
<th scope="col" class="text-wrap" title="Edit Chant"></th>
{% endif %}
</td>
{% if user_can_edit_chant %}
</tr>
</thead>
<tbody>
{% for chant in chants %}
<tr>
<td class="text-wrap" style="text-align:center" title="{{ source.title }}">{{ source.siglum|default:"" }}</td>
<td class="text-wrap" style="text-align:center"><b>{{ chant.folio|default:"" }}</b></td>
<td class="text-wrap" style="text-align:center">{{ chant.c_sequence|default_if_none:"" }}</td> {# default_if_none: sometimes, c_sequence is 0, and should still be displayed #}
<td class="text-wrap">
<a href="{% url 'chant-detail' chant.id %}"><b>{{ chant.incipit|default:"" }}</b></a>
<p>{{ chant.manuscript_full_text_std_spelling|default:"" }}<br>
{% if chant.volpiano %}
<span style="font-family: volpiano; font-size:25px">{{ chant.volpiano|default:"" }}</span>
{% endif %}
</p>
</td>
<td class="text-wrap" style="text-align:center">
{% if chant.feast %}
<a href="{% url 'feast-detail' chant.feast.id %}" title="{{ chant.feast.description }}">{{ chant.feast.name|default:"" }}</a>
{% endif %}
</td>
<td class="text-wrap" style="text-align:center">
{% if chant.office %}
<a href="{% url 'office-detail' chant.office.id %}" title="{{ chant.office.description }}">{{ chant.office.name|default:"" }}</a>
{% endif %}
</td>
<td class="text-wrap" style="text-align:center">
<a href="{% url 'source-edit-chants' chant.source.id %}?pk={{ chant.id }}&folio={{ chant.folio }}&ref=chant-list">Edit</a>
{% if chant.genre %}
<a href="{% url 'genre-detail' chant.genre.id %}" title="{{ chant.genre.description }}">{{ chant.genre.name|default:"" }}</a>
{% endif %}
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% include "pagination.html" %}
{% else %}
No chants found.
{% endif %}
<td class="text-wrap" style="text-align:center">{{ chant.position|default:"" }}</td>
<td class="text-wrap" style="text-align:center">
<a href="{{ chant.get_ci_url }}" target="_blank">{{ chant.cantus_id|default:"" }}</a>
</td>
<td class="text-wrap" style="text-align:center">{{ chant.mode|default:"" }}</td>
<td class="text-wrap" style="text-align:center">
{% if exists_on_cantus_ultimus %}
<a href="https://cantus.simssa.ca/manuscript/{{ source.id }}/?folio={{ chant.folio }}&chant={{ chant.c_sequence }}" target="_blank">
Image
</a>
{% elif chant.image_link %}
<a href="{{ chant.image_link }}" target="_blank">Image</a>
{% endif %}
</td>
{% if user_can_edit_chant %}
<td class="text-wrap" style="text-align:center">
<a href="{% url 'source-edit-chants' source.id %}?pk={{ chant.id }}&folio={{ chant.folio }}&ref=chant-list">Edit</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% include "pagination.html" %}
{% else %}
No chants found.
{% endif %}
{% endwith %}
</div>

<div class="col p-0 sidebar">
Expand Down Expand Up @@ -165,11 +170,14 @@ <h4><a href="{% url 'source-detail' source.id %}" title="{{ source.title }}">{{
<br>
<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>
{% if source.exists_on_cantus_ultimus %}
<a href="https://cantus.simssa.ca/manuscript/{{ source.id }}" class="guillemet" target="_blank">View inventory with images</a>
{% endif %}
{% if source.image_link %}
<a href="{{ source.image_link }}" class="guillemet" target="_blank">View images on external site</a>
{% endif %}
<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 source</a>
{% if source.image_link %}
<a href="{{ source.image_link }}" class="guillemet" target="_blank">Images</a>
{% endif %}
<a href="{% url "melody-search" %}?source={{ source.id }}" class="guillemet" target="_blank">Search melodies in this source</a>
<a href="//cantusindex.org/analyse?src={{ source.id }}&db=CD" class="guillemet" target="_blank">Analyse this source (Cantus Analysis Tool)</a>
</small>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ <h3>Create Chant</h3>
{{ form.manuscript_full_text_std_spelling }}
<p>
<small class="text-muted">{{ form.manuscript_full_text_std_spelling.help_text }}
For more information, consult <a href="/field-descriptions/#Fulltext" target="_blank">Fields and Content Descriptions</a>.
For more information, consult <a href="/description/#Fulltext" target="_blank">Fields and Content Descriptions</a>.
</small>
</p>
</div>
Expand Down
14 changes: 13 additions & 1 deletion django/cantusdb_project/main_app/templates/chant_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ <h3>{{ chant.incipit }}</h3>
<a href="{{ chant.image_link }}" target="_blank" style="word-break: break-all">{{ chant.image_link }}</a>
</dd>
{% endif %}
{% if exists_on_cantus_ultimus %}
<dt>Image link (Cantus Ultimus)</dt>
<dd>
<a href="https://cantus.simssa.ca/manuscript/{{ chant.source.id }}/?folio={{ chant.folio }}&chant={{ chant.c_sequence }}" target="_blank" style="word-break: break-all">
https://cantus.simssa.ca/manuscript/{{ chant.source.id }}/?folio={{ chant.folio }}&chant={{ chant.c_sequence }}
</a>
</dd>
{% endif %}
</dl>
{% if chant.cantus_id %}
<h4 id="concordances">List of concordances</h4>
Expand Down Expand Up @@ -271,7 +279,11 @@ <h4>List of melodies</h4>
&nbsp;<a href="{% url "browse-chants" source.id %}?folio={{ next_folio }}">> {{ next_folio }}</a>
{% endif %}

{% if chant.image_link %}
{% if exists_on_cantus_ultimus %}
<a href="https://cantus.simssa.ca/manuscript/{{ chant.source.id }}/?folio={{ chant.folio }}&chant={{ chant.c_sequence }}" class="guillemet" target="_blank">
Display facsimile <b>({{ chant.folio }})
</a>
{% elif chant.image_link %}
<a href={{ chant.image_link }} class="guillemet" target="_blank">Display facsimile <b>({{ chant.folio }})</b></a>
{% endif %}

Expand Down
2 changes: 2 additions & 0 deletions django/cantusdb_project/main_app/templates/pagination.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load helper_tags %} {# for url_add_get_params #}


<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
Expand Down Expand Up @@ -29,4 +30,5 @@
{% endif %}
</span>
</div>

<span class="current">Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</span>
Loading

0 comments on commit 94cde34

Please sign in to comment.