Skip to content

Commit

Permalink
Merge pull request #1558 from DDMAL/develop
Browse files Browse the repository at this point in the history
Merge develop into staging, 10 July
  • Loading branch information
dchiller authored Jul 10, 2024
2 parents 7c94d6c + f17e934 commit dfb226f
Show file tree
Hide file tree
Showing 50 changed files with 3,321 additions and 2,683 deletions.
16 changes: 5 additions & 11 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 @@ -24,17 +25,10 @@ server {
expires modified +24h;
}

error_page 500 /500.html;
location = /500.html {
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 /;
}
}
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 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 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 %}
42 changes: 39 additions & 3 deletions django/cantusdb_project/cantusindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
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 @@ -132,7 +134,7 @@ def get_suggested_fulltext(cantus_id: str) -> Optional[str]:
return suggested_fulltext


def get_merged_cantus_ids() -> Optional[list]:
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
Expand All @@ -150,23 +152,57 @@ def get_merged_cantus_ids() -> Optional[list]:
# 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"https://cantusindex.org{endpoint_path}"
uri: str = f"{OLD_CANTUS_INDEX_DOMAIN}{endpoint_path}"
try:
response: requests.Response = requests.get(uri, timeout=DEFAULT_TIMEOUT)
except requests.exceptions.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
2 changes: 1 addition & 1 deletion django/cantusdb_project/main_app/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from main_app.admin.notation import NotationAdmin
from main_app.admin.office import OfficeAdmin
from main_app.admin.provenance import ProvenanceAdmin
from main_app.admin.rism_siglum import RismSiglumAdmin
from main_app.admin.segment import SegmentAdmin
from main_app.admin.sequence import SequenceAdmin
from main_app.admin.source import SourceAdmin
from main_app.admin.institution import InstitutionAdmin
from main_app.admin.institution_identifier import InstitutionIdentifierAdmin
from main_app.admin.project import ProjectAdmin
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

@admin.register(InstitutionIdentifier)
class InstitutionIdentifierAdmin(BaseModelAdmin):
list_display = ('identifier', 'identifier_type')
list_display = ("identifier", "identifier_type")
raw_id_fields = ("institution",)
9 changes: 9 additions & 0 deletions django/cantusdb_project/main_app/admin/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin

from main_app.admin.base_admin import BaseModelAdmin
from main_app.models import Project


@admin.register(Project)
class ProjectAdmin(BaseModelAdmin):
search_fields = ("name",)
11 changes: 0 additions & 11 deletions django/cantusdb_project/main_app/admin/rism_siglum.py

This file was deleted.

Loading

0 comments on commit dfb226f

Please sign in to comment.