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

Merge staging into production #1500

Merged
merged 139 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
e0f51f4
dependencies: upgrade django-debug-toolbar
lucasmarchd01 May 16, 2024
97df2c5
settings.py: add docker internal IP for django debug toolbar
lucasmarchd01 May 16, 2024
4f29e56
settings: add show toolbar callback to debug toolbar config
lucasmarchd01 May 21, 2024
5bbbc1c
Merge pull request #1464 from lucasmarchd01/issue-1457
lucasmarchd01 May 21, 2024
b9d9aed
cantusindex.py: add get_merged_chants
lucasmarchd01 May 22, 2024
6d4e502
forms: change help text for Source title field
lucasmarchd01 May 22, 2024
1707f76
source: change help text for title field
lucasmarchd01 May 22, 2024
48602bc
templates: replace instances of "manuscript" with "source"
lucasmarchd01 May 22, 2024
5504f98
my sources sidebar: order sources by "date_updated"
lucasmarchd01 May 22, 2024
032bb3b
my sources: order sources by "date_updated"
lucasmarchd01 May 22, 2024
0e1945d
Add Benedicamus Domino-related fields to base_chant model
dchiller May 23, 2024
68c1294
Update ChantCreate and ChantEdit forms and widgets for BD fields
dchiller May 23, 2024
c927f77
Add BD fields to chant_create template
dchiller May 23, 2024
d837f5c
Add BD fields to chant_edit template
dchiller May 23, 2024
e6518b0
Merge pull request #1470 from lucasmarchd01/issue-1097-2
lucasmarchd01 May 23, 2024
00848ce
Merge pull request #1472 from lucasmarchd01/issue-1468
lucasmarchd01 May 23, 2024
dd53bf9
Remove unnecessary comments in forms.py
dchiller May 23, 2024
c3775c6
Merge pull request #1473 from dchiller/add-bd-fields
dchiller May 23, 2024
99cb751
Merge pull request #1475 from DDMAL/develop
dchiller May 23, 2024
f11bf8d
cantusindex: add get_merged_cantus_ids
lucasmarchd01 May 24, 2024
b0c20f5
management: add_cantus_index_merge_events command for cron job
lucasmarchd01 May 24, 2024
95810ff
update docstring
lucasmarchd01 May 24, 2024
26dfdcb
remove unused import
lucasmarchd01 May 24, 2024
c38ce8a
fix spacing
lucasmarchd01 May 24, 2024
aaa8e7d
management: remove unused import
lucasmarchd01 May 24, 2024
c565828
management: fix typing for date filter
lucasmarchd01 May 27, 2024
c2ab71b
Merge pull request #1479 from lucasmarchd01/issue-877
lucasmarchd01 May 27, 2024
8bfbbe2
source list: add .distinct() to queryset
lucasmarchd01 May 27, 2024
2baca6a
static: add footer logos
lucasmarchd01 May 27, 2024
9b17a33
static: delete unused logos
lucasmarchd01 May 27, 2024
1604db1
base: add footer logos and adjust styling
lucasmarchd01 May 27, 2024
2937416
base: change "Cantus Team" list
lucasmarchd01 May 27, 2024
bcfccb8
static: add creative commons logo to footer
lucasmarchd01 May 27, 2024
56ce8f5
static: remove cantus database logo
lucasmarchd01 May 27, 2024
69a7dae
Merge pull request #1481 from lucasmarchd01/issue-1480
lucasmarchd01 May 28, 2024
f316f85
static: remove neh logo from footer
lucasmarchd01 May 28, 2024
f122d91
footer: Change development and maintenance link
lucasmarchd01 May 28, 2024
5fb051c
footer: remove errant spaces
lucasmarchd01 May 28, 2024
c030b9b
footer: Change "DDMAL" to "DDMAL Lab"
lucasmarchd01 May 29, 2024
fcf31af
Merge pull request #1482 from lucasmarchd01/issue-1405
lucasmarchd01 May 29, 2024
e1379ce
Upgrade to volpiano-display-utilities 1.1.3
dchiller May 29, 2024
f8146b8
Use safe template filter for source.indexing_notes in sidebar
dchiller May 29, 2024
7c84fc7
Update container name in db_backup.sh
dchiller May 30, 2024
f2318bf
Specify container names in docker-compose files
dchiller May 30, 2024
07db05e
Change docker-compose to docker compose in cron/management/manage.sh
dchiller May 30, 2024
d8a8271
Merge pull request #1487 from dchiller/upgrade-volpiano-display-utili…
dchiller May 30, 2024
2752216
Merge pull request #1488 from dchiller/i1486-inventory-notes
dchiller May 30, 2024
a50dc82
build(deps): bump requests from 2.31.0 to 2.32.2
dependabot[bot] May 30, 2024
e0b5a97
Merge pull request #1490 from dchiller/i1489-fix-backup-cron
dchiller May 30, 2024
0f11464
chant search: allow sortable headers from global search bar
lucasmarchd01 May 31, 2024
ed6073a
tests: add tests for chant search using global search bar
lucasmarchd01 Jun 3, 2024
490ce55
Merge pull request #1497 from lucasmarchd01/issue-1089
lucasmarchd01 Jun 3, 2024
908f29e
Merge pull request #1494 from DDMAL/dependabot/pip/requests-2.32.2
lucasmarchd01 Jun 3, 2024
781387e
Assign sequences to segment in command
dchiller Jun 3, 2024
d21f42c
Merge pull request #1499 from dchiller/assign-sequences-to-segments-too
dchiller Jun 4, 2024
668dd22
Merge pull request #1498 from DDMAL/develop
dchiller Jun 4, 2024
3a1c328
chant edit: preserve proofreader fields for contributor changes
lucasmarchd01 Jun 4, 2024
ea46ca4
chant edit: edit typing
lucasmarchd01 Jun 4, 2024
3b3391d
chant edit: change chant object retrieval
lucasmarchd01 Jun 4, 2024
9c64810
chant view: remove unused import
lucasmarchd01 Jun 4, 2024
fda5cc0
Update manage.sh
dchiller Jun 5, 2024
ef589de
edit chant: add typing for user
lucasmarchd01 Jun 5, 2024
38fbd3c
my sources: fix ordering of sources in list and sidebar
lucasmarchd01 Jun 5, 2024
4f3311d
tests: black formatting
lucasmarchd01 Jun 5, 2024
7dc3d2e
Merge pull request #1503 from DDMAL/i1502-manage-docker-path
dchiller Jun 5, 2024
94fba8c
Merge pull request #1504 from lucasmarchd01/issue-1468-2
lucasmarchd01 Jun 5, 2024
3dbbf0b
chant edit: simplify with set() method
lucasmarchd01 Jun 5, 2024
1f70a5d
Merge pull request #1501 from lucasmarchd01/issue-1491
lucasmarchd01 Jun 5, 2024
228eb45
Fixed: Add a migration for changes to Source model
ahankinson Jun 6, 2024
914fbf3
Merge pull request #1512 from DDMAL/fixed-1511-add-missing-migration
lucasmarchd01 Jun 6, 2024
bea8ded
Fixed: Add institution models
ahankinson Jun 6, 2024
49146a3
Merge branch 'develop' into fixed-1505-institutions
ahankinson Jun 6, 2024
f9c0994
Fixed: Break up admin.py
ahankinson Jun 6, 2024
ae46096
Merge branch 'fixed-1510-admin' into fixed-1505-institutions
ahankinson Jun 6, 2024
4462359
Fixed: Add institutions to the new admin layout
ahankinson Jun 6, 2024
4546291
cantusindex: fix TypeError in get_suggested_chant
lucasmarchd01 Jun 7, 2024
6638001
Merge pull request #1517 from lucasmarchd01/issue-1515
lucasmarchd01 Jun 7, 2024
5bc4114
Merge pull request #1513 from DDMAL/fixed-1510-admin
dchiller Jun 11, 2024
e3a6279
refactor(nginx): Consolidate static files for custom error pages
dchiller Jun 11, 2024
b11f202
feat(nginx): Add custom 500 error page
dchiller Jun 11, 2024
62f418b
build(nginx): Add nginx password file
dchiller Jun 11, 2024
76ee930
style(nginx): Add missing space to cantusdb.conf.development
dchiller Jun 11, 2024
75cf156
Fixed: Expand institution model
ahankinson Jun 11, 2024
98b9c58
Merge branch 'develop' into fixed-1505-institutions
ahankinson Jun 11, 2024
efae0ea
Merge pull request #1520 from dchiller/nginx-password-and-error-page
dchiller Jun 11, 2024
5d9998b
Add former sigla to institution records
ahankinson Jun 11, 2024
7734cde
Comment out chant segment and BD-specific fields on chant forms
dchiller Jun 12, 2024
2050973
Merge pull request #1522 from dchiller/i1521-remove-segment-from-chan…
dchiller Jun 12, 2024
4ac2d91
Enhance the display of the institution identifiers
ahankinson Jun 12, 2024
1d961f6
build: use specific version of psycopg-binary package
dchiller Jun 12, 2024
3c270d8
fix: Account for bad alignment flag in EditSyllabificationView
dchiller Jun 12, 2024
226cb5b
feat: Add github actions for django tests
dchiller Jun 12, 2024
5605ba6
Adjust string formatting
ahankinson Jun 13, 2024
2d213fd
Merge branch 'develop' into fixed-1505-institutions
ahankinson Jun 13, 2024
bd22850
Fixed: Remove the RISM Sigla table
ahankinson Jun 13, 2024
4f1046d
feat(cantusindex): add json-text api function
lucasmarchd01 Jun 13, 2024
8992874
feat(urls): add cantus index input tool
lucasmarchd01 Jun 13, 2024
bc9b1ec
feat(chant create): add input tool card on sidebar
lucasmarchd01 Jun 13, 2024
e9c62e9
feat(ci search): add input tool search window page
lucasmarchd01 Jun 13, 2024
4b6e357
feat(cisearchview): add ci search view
lucasmarchd01 Jun 13, 2024
f4a0a0c
fix(cantusindex): fix typing and bug with json parsing
lucasmarchd01 Jun 13, 2024
d673f50
fix(cantusindex): fix error handling
lucasmarchd01 Jun 13, 2024
4c92016
Merge pull request #1514 from DDMAL/fixed-1505-institutions
dchiller Jun 13, 2024
6266757
Merge pull request #1526 from dchiller/add-test-runner
dchiller Jun 13, 2024
7c94d6c
Merge pull request #1523 from DDMAL/develop
dchiller Jun 13, 2024
e48c6c3
Merge branch 'develop' into fixed-1508-siglum-2
dchiller Jun 13, 2024
96f5a7f
refactor(nginx): change location of custom error pages
dchiller Jun 13, 2024
c987e1c
Merge pull request #1529 from DDMAL/fixed-1508-siglum-2
ahankinson Jun 14, 2024
ea9a0f2
Fixed: Allow superusers all access
ahankinson Jun 14, 2024
2c4fb30
fix(nginx): remove placeholder .htpasswd file
dchiller Jun 14, 2024
e50b82f
Merge pull request #1531 from DDMAL/fixed-1527-permissions
dchiller Jun 14, 2024
5cee181
fix(search bar): show search bar dynamic results on all pages
dchiller Jun 14, 2024
d5de832
feat(cantusindex): add genre dal selector
lucasmarchd01 Jun 17, 2024
050a951
fix(cantusindex): fix genre dal option selector on cantus index tool
lucasmarchd01 Jun 17, 2024
971a744
refactor(cantusindex): rewrite docstrings and remove errant code
lucasmarchd01 Jun 17, 2024
f7755c2
refactor(cantusindex): remove comment
lucasmarchd01 Jun 17, 2024
58f6563
feat(frontend): sandwich main content with sidebar on narrow screens
dchiller Jun 17, 2024
676268d
refactor(cantusindex): add comment for dal option selector
lucasmarchd01 Jun 17, 2024
94e6c57
Merge pull request #1530 from dchiller/refactor-error-pgs-and-psswd
dchiller Jun 17, 2024
71823a6
fix(cantusindex): fix typing in CISearchView
lucasmarchd01 Jun 18, 2024
bcc3b21
Merge pull request #1537 from dchiller/modify-sidebar
dchiller Jun 18, 2024
7283630
Merge branch 'develop' into issue-1391
lucasmarchd01 Jun 18, 2024
1b803aa
refactor(cantusindex): modify message on ci search
lucasmarchd01 Jun 18, 2024
6da51fa
Merge pull request #1538 from lucasmarchd01/issue-1391
lucasmarchd01 Jun 18, 2024
2dfc484
feat!(models): add Project model
dchiller Jun 18, 2024
0ea4430
feat(commands): Create assign_sequences_to_bower_project command
dchiller Jun 18, 2024
1216a2d
fix(templates): fix spelling of Clavis Sequentiarum in dropdown
dchiller Jun 18, 2024
64de5bc
feat(models): Add Project model admin
dchiller Jun 18, 2024
8084cfa
feat(chant-create;chant-edit): Add project field and benedicamus domi…
dchiller Jun 18, 2024
6807731
fix(tests): Add Project to make_fake_chant
dchiller Jun 18, 2024
8361d23
fix(tests): Remove segment from Chant view tests
dchiller Jun 18, 2024
017a67f
test(cantusindex): add missing tests
lucasmarchd01 Jun 20, 2024
8ec1be5
test(cantusindex): add tests for CISearchView
lucasmarchd01 Jun 20, 2024
da68ff5
fix(cantusindex): convert zip iterator to list in CISearchView context
lucasmarchd01 Jun 20, 2024
653bf52
Merge pull request #1552 from lucasmarchd01/issue-1391
lucasmarchd01 Jun 21, 2024
b9c594c
fix(forms): Make chant project field optional
dchiller Jul 10, 2024
97c7bd7
refactor: Remove unused import in widgets.py
dchiller Jul 10, 2024
f17e934
Merge pull request #1548 from dchiller/i1541-return-segment-to-source…
dchiller Jul 10, 2024
dfb226f
Merge pull request #1558 from DDMAL/develop
dchiller Jul 10, 2024
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
29 changes: 29 additions & 0 deletions .github/workflows/django_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: django-tests
on:
pull_request:
types: [opened, synchronize]
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: mkdir -p config/envs
- uses: SpicyPizza/[email protected]
with:
envkey_POSTGRES_DB: test_cantusdb
envkey_POSTGRES_USER: test_user
envkey_POSTGRES_HOST: postgres
envkey_POSTGRES_PORT: 5432
envkey_PROJECT_ENVIRONMENT: PRODUCTION
envkey_CANTUSDB_STATIC_ROOT: /path/to/static
envkey_CANTUSDB_MEDIA_ROOT: /path/to/media
envkey_CANTUSDB_HOST: somehost
envkey_CANTUSDB_SECRET_KEY: "hereisakey1234"
envkey_POSTGRES_PASSWORD: woahagreatpasswordabc
envkey_AWS_EMAIL_HOST_USER: test_user
envkey_AWS_EMAIL_HOST_PASSWORD: test_password
directory: config/envs
file_name: dev_env
- run: docker compose -f docker-compose-development.yml build
- run: docker compose -f docker-compose-development.yml up -d
- run: docker compose -f docker-compose-development.yml exec -T django python manage.py test main_app.tests
26 changes: 6 additions & 20 deletions config/nginx/conf.d/cantusdb.conf.development
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_intercept_errors on;
}

location /static {
Expand All @@ -23,26 +24,11 @@ server {
alias /resources/api_cache/concordances.json;
expires modified +24h;
}

location = /style.css {
root /;
}
location = /background.jpg {
root /;
}
location = /CantusLogoSmall.gif {
root /;
}
location = /favicon.ico {
root /;
}

error_page 502 /502.html;
location = /502.html {
root /;
}
error_page 504 /504.html;
location = /504.html {
error_page 500 /error_pages/500.html;
error_page 502 /error_pages/502.html;
error_page 504 /error_pages/504.html;
location /error_pages {
root /;
}
}
}
2 changes: 1 addition & 1 deletion cron/management/manage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
DOCKER_COMPOSE_FILE=$1 # This is the path to the docker-compose file.
COMMAND=$2 # This is the command to execute.

/usr/local/bin/docker-compose -f $DOCKER_COMPOSE_FILE exec -T django python manage.py $COMMAND
/usr/bin/docker compose -f $DOCKER_COMPOSE_FILE exec -T django python manage.py $COMMAND
6 changes: 3 additions & 3 deletions cron/postgres/db_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ BACKUP_FILENAME=$(date "+%Y-%m-%dT%H:%M:%S").sql.gz # This is th

# Create the backup and copy it to the daily backup directory
mkdir -p $BACKUP_DIR/daily $BACKUP_DIR/weekly $BACKUP_DIR/monthly $BACKUP_DIR/yearly
/usr/bin/docker exec cantusdb_postgres_1 /usr/local/bin/postgres_backup.sh $BACKUP_FILENAME
/usr/bin/docker cp cantusdb_postgres_1:/var/lib/postgresql/backups/$BACKUP_FILENAME $BACKUP_DIR/daily
/usr/bin/docker exec cantusdb_postgres_1 rm /var/lib/postgresql/backups/$BACKUP_FILENAME
/usr/bin/docker exec cantusdb-postgres-1 /usr/local/bin/postgres_backup.sh $BACKUP_FILENAME
/usr/bin/docker cp cantusdb-postgres-1:/var/lib/postgresql/backups/$BACKUP_FILENAME $BACKUP_DIR/daily
/usr/bin/docker exec cantusdb-postgres-1 rm /var/lib/postgresql/backups/$BACKUP_FILENAME

# Manage retention of daily backups
FILES_TO_REMOVE=$(ls -td $BACKUP_DIR/daily/* | tail -n +8)
Expand Down
61 changes: 30 additions & 31 deletions django/cantusdb_project/articles/templates/article_detail.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
{% extends "base.html" %}
{% extends "base_page_with_side_cards.html" %}
{% load helper_tags %} {# for recent_articles #}
{% block content %}
<div class="container">
<title>{{ article.title }} | Cantus Manuscript Database</title>
{% block title %}
<title>{{ article.title }} | Cantus Database</title>
{% endblock %}

{% block uppersidebar %}
<div class="search-bar mb-3">
{% include "global_search_bar.html" %}
</div>
{% endblock %}

{% block maincontent %}
<h3>
{{ article.title }}
</h3>
<div class="row">
<div class="p-3 col-lg-8 bg-white rounded main-content">
<h3>
{{ article.title }}
</h3>
<div class="row">
<div class="col">
<div class="container">
<div class="container text-wrap">
<small>Submitted by <a href="{% url 'user-detail' article.author.id %}">{{ article.author }}</a> on {{ article.date_created|date:"D, m/d/Y - H:i" }}</small>
<div style="padding-top: 1em;">
{{ article.body.html|safe }}
</div>
</div>
<div class="col">
<div class="container">
<div class="container text-wrap">
<small>Submitted by <a href="{% url 'user-detail' article.author.id %}">{{ article.author }}</a> on {{ article.date_created|date:"D, m/d/Y - H:i" }}</small>
<div style="padding-top: 1em;">
{{ article.body.html|safe }}
</div>
</div>
</div>
</div>
<div class="col p-0 sidebar">
<div class="search-bar mb-3">
{% include "global_search_bar.html" %}
</div>
<div class="card mt-3 w-100">
<div class="card-header">
What's New
</div>
<div class="card-body">
{% recent_articles %}
</div>
</div>
</div>
{% endblock %}
{% block lowersidebar %}
<div class="card">
<div class="card-header">
What's New
</div>
<div class="card-body">
{% recent_articles %}
</div>
</div>

</div>
{% endblock %}
70 changes: 33 additions & 37 deletions django/cantusdb_project/articles/templates/article_list.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
{% extends "base.html" %}
{% load helper_tags %} {# for recent_articles #}
{% block content %}
<div class="container">
<title>What's New | Cantus Manuscript Database</title>
{% extends "base_page_with_side_cards.html" %}
{% load helper_tags %} {# for recent_articles #}\
{% block title %}
<title>What's New | Cantus Database</title>
{% endblock %}
{% block uppersidebar %}
<div class="search-bar mb-3">
{% include "global_search_bar.html" %}
</div>
{% endblock %}
{% block maincontent %}
<h3>What's New</h3>
{% for article in articles %}
<div class="row">
<div class="p-3 col-lg-8 bg-white rounded main-content">
<h3>What's New</h3>
{% for article in articles %}
<div class="row">
<div class="col">
<small>{{ article.date_created|date:"D, m/d/Y - H:i" }}</small>
<h4>
<a href="{% url 'article-detail' article.id %}">{{ article.title }}</a>
</h4>
<div class="container">
<small>
{{ article.body.html|safe|truncatechars_html:3000 }}
</small>
</div>
</div>
<div class="col">
<small>{{ article.date_created|date:"D, m/d/Y - H:i" }}</small>
<h4>
<a href="{% url 'article-detail' article.id %}">{{ article.title }}</a>
</h4>
<div class="container">
<small>
{{ article.body.html|safe|truncatechars_html:3000 }}
</small>
</div>
{% endfor %}
{% include "pagination.html" %}
<br>
</div>
<div class="col p-0 sidebar">
<div class="search-bar mb-3">
{% include "global_search_bar.html" %}
</div>

<div class="card mt-3 w-100">
<div class="card-header">
What's New
</div>
<div class="card-body">
{% recent_articles %}
</div>
</div>
</div>
{% endfor %}
{% include "pagination.html" %}
{% endblock %}
{% block lowersidebar %}
<div class="card">
<div class="card-header">
What's New
</div>
<div class="card-body">
{% recent_articles %}
</div>
</div>
</div>
{% endblock %}
3 changes: 3 additions & 0 deletions django/cantusdb_project/cantusdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
"debug_toolbar.panels.redirects.RedirectsPanel",
"debug_toolbar.panels.profiling.ProfilingPanel",
},
"SHOW_TOOLBAR_CALLBACK": lambda request: (
False if request.headers.get("x-requested-with") == "XMLHttpRequest" else True
),
}

INTERNAL_IPS = [
Expand Down
83 changes: 79 additions & 4 deletions django/cantusdb_project/cantusindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import requests
from typing import Optional, Union, Callable
from main_app.models import Genre
import json
from requests.exceptions import SSLError, Timeout, HTTPError

CANTUS_INDEX_DOMAIN: str = "https://cantusindex.uwaterloo.ca"
OLD_CANTUS_INDEX_DOMAIN: str = "https://cantusindex.org"
DEFAULT_TIMEOUT: float = 2 # seconds
NUMBER_OF_SUGGESTED_CHANTS: int = 3 # this number can't be too large,
# since for each suggested chant, we make a request to Cantus Index.
Expand Down Expand Up @@ -90,9 +93,12 @@ def get_suggested_chant(
# mostly, in case of a timeout within get_json_from_ci_api
return None

fulltext: str = json["info"]["field_full_text"]
incipit: str = " ".join(fulltext.split(" ")[:5])
genre_name: str = json["info"]["field_genre"]
try:
fulltext: str = json["info"]["field_full_text"]
incipit: str = " ".join(fulltext.split(" ")[:5])
genre_name: str = json["info"]["field_genre"]
except TypeError:
return None
genre_id: Optional[int] = None
try:
genre_id = Genre.objects.get(name=genre_name).id
Expand All @@ -112,7 +118,7 @@ def get_suggested_chant(
}


def get_suggested_fulltext(cantus_id: str) -> str:
def get_suggested_fulltext(cantus_id: str) -> Optional[str]:
endpoint_path: str = f"/json-cid/{cantus_id}"
json: Union[dict, list, None] = get_json_from_ci_api(endpoint_path)

Expand All @@ -128,6 +134,75 @@ def get_suggested_fulltext(cantus_id: str) -> str:
return suggested_fulltext


def get_merged_cantus_ids() -> Optional[list[Optional[dict]]]:
"""Retrieve merged Cantus IDs from the Cantus Index API (/json-merged-chants)

This function sends a request to the Cantus Index API endpoint for merged chants
and retrieves the response. The response is expected to be a list of dictionaries,
each containing information about a merged Cantus ID, including the old Cantus ID,
the new Cantus ID, and the date of the merge.

Returns:
Optional[list]: A list of dictionaries representing merged chant information,
or None if there was an error retrieving the data or the response format is invalid.

"""
endpoint_path: str = "/json-merged-chants"

# We have to use the old CI domain since the API is still not available on
# cantusindex.uwaterloo.ca. Once it's available, we can use get_json_from_ci_api
# json: Union[dict, list, None] = get_json_from_ci_api(endpoint_path)
uri: str = f"{OLD_CANTUS_INDEX_DOMAIN}{endpoint_path}"
try:
response: requests.Response = requests.get(uri, timeout=DEFAULT_TIMEOUT)
except (SSLError, Timeout, HTTPError):
return None
if not response.status_code == 200:
return None
response.encoding = "utf-8-sig"
raw_text: str = response.text
text_without_bom: str = raw_text.encode().decode("utf-8-sig")
if not text_without_bom:
return None
merge_events: list = json.loads(text_without_bom)

if not isinstance(merge_events, list):
return None
return merge_events


def get_ci_text_search(search_term: str) -> Optional[list[Optional[dict]]]:
"""Fetch data from Cantus Index for a given search term.
To do a text search on CI, we use 'https://cantusindex.org/json-text/<text to search>
"""

# We have to use the old CI domain since this API is still not available on
# cantusindex.uwaterloo.ca. Once it's available, we can use get_json_from_ci_api
# json: Union[dict, list, None] = get_json_from_ci_api(uri)
endpoint_path: str = f"/json-text/{search_term}"
uri: str = f"{OLD_CANTUS_INDEX_DOMAIN}{endpoint_path}"
try:
response: requests.Response = requests.get(
uri,
timeout=DEFAULT_TIMEOUT,
)
except (SSLError, Timeout, HTTPError):
return None
if not response.status_code == 200:
return None
response.encoding = "utf-8-sig"
raw_text: str = response.text
text_without_bom: str = raw_text.encode().decode("utf-8-sig")
if not text_without_bom:
return None
text_search_results: list = json.loads(text_without_bom)
# if cantus index returns an empty table
if not text_search_results or not isinstance(text_search_results, list):
return None

return text_search_results


def get_json_from_ci_api(
path: str, timeout: float = DEFAULT_TIMEOUT
) -> Union[dict, list, None]:
Expand Down
Loading
Loading