Skip to content

Commit

Permalink
Merge branch 'develop' into add-institution-views
Browse files Browse the repository at this point in the history
  • Loading branch information
ahankinson committed Aug 9, 2024
2 parents 4e1064e + 65f9d4f commit 40391a9
Show file tree
Hide file tree
Showing 38 changed files with 412 additions and 328 deletions.
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 @@ -4,7 +4,7 @@
from main_app.admin.feast import FeastAdmin
from main_app.admin.genre import GenreAdmin
from main_app.admin.notation import NotationAdmin
from main_app.admin.office import OfficeAdmin
from main_app.admin.service import ServiceAdmin
from main_app.admin.provenance import ProvenanceAdmin
from main_app.admin.segment import SegmentAdmin
from main_app.admin.sequence import SequenceAdmin
Expand Down
16 changes: 14 additions & 2 deletions django/cantusdb_project/main_app/admin/chant.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
from django.contrib import admin

from main_app.admin.base_admin import EXCLUDE, READ_ONLY, BaseModelAdmin
from main_app.admin.filters import InputFilter
from main_app.forms import AdminChantForm
from main_app.models import Chant


class SourceKeyFilter(InputFilter):
parameter_name = "source_id"
title = "Source ID"

def queryset(self, request, queryset):
if self.value():
return queryset.filter(source_id=self.value())


@admin.register(Chant)
class ChantAdmin(BaseModelAdmin):

def get_queryset(self, request):
return (
super()
.get_queryset(request)
.select_related("source__holding_institution", "genre", "office")
.select_related("source__holding_institution", "genre", "service")
)

@admin.display(description="Source Siglum")
Expand All @@ -30,13 +40,15 @@ def get_source_siglum(self, obj):
"incipit",
"cantus_id",
"id",
"source__holding_institution__siglum"
)

readonly_fields = READ_ONLY + ("incipit",)

list_filter = (
SourceKeyFilter,
"genre",
"office",
"service",
)
exclude = EXCLUDE + (
"col1",
Expand Down
11 changes: 0 additions & 11 deletions django/cantusdb_project/main_app/admin/office.py

This file was deleted.

4 changes: 2 additions & 2 deletions django/cantusdb_project/main_app/admin/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_queryset(self, request):
return (
super()
.get_queryset(request)
.select_related("source__holding_institution", "genre", "office")
.select_related("source__holding_institution", "genre", "service")
)

@admin.display(description="Source Siglum")
Expand All @@ -34,7 +34,7 @@ def get_source_siglum(self, obj):
list_display = ("incipit", "get_source_siglum", "genre")
list_filter = (
"genre",
"office",
"service",
)
raw_id_fields = (
"source",
Expand Down
11 changes: 11 additions & 0 deletions django/cantusdb_project/main_app/admin/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin

from main_app.admin.base_admin import BaseModelAdmin
from main_app.forms import AdminServiceForm
from main_app.models import Service


@admin.register(Service)
class ServiceAdmin(BaseModelAdmin):
search_fields = ("name",)
form = AdminServiceForm
30 changes: 15 additions & 15 deletions django/cantusdb_project/main_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from .models import (
Chant,
Office,
Service,
Genre,
Notation,
Feast,
Expand Down Expand Up @@ -37,9 +37,9 @@ class NameModelChoiceField(forms.ModelChoiceField):
"""
A custom ModelChoiceField that overrides the label_from_instance method
to display the object's name attribute instead of str(object).
This field is specifically designed for handling genre and office objects.
This field is specifically designed for handling genre and service objects.
Rather than displaying the name along with its description, sometimes we
only want the shorthand notation for the genre and office objects.
only want the shorthand notation for the genre and service objects.
(Eg. [AV] Antiphon verse --> AV)
"""

Expand Down Expand Up @@ -78,7 +78,7 @@ class Meta:
"marginalia",
"folio",
"c_sequence",
"office",
"service",
"genre",
"position",
"cantus_id",
Expand Down Expand Up @@ -113,7 +113,7 @@ class Meta:
"marginalia": TextInputWidget(),
# folio: defined below (required)
# c_sequence: defined below (required)
"office": autocomplete.ModelSelect2(url="office-autocomplete"),
"service": autocomplete.ModelSelect2(url="service-autocomplete"),
"genre": autocomplete.ModelSelect2(url="genre-autocomplete"),
"position": TextInputWidget(),
"cantus_id": TextInputWidget(),
Expand Down Expand Up @@ -284,7 +284,7 @@ class Meta:
"folio",
"c_sequence",
"feast",
"office",
"service",
"genre",
"position",
"cantus_id",
Expand Down Expand Up @@ -318,7 +318,7 @@ class Meta:
# folio: defined below (required)
# c_sequence: defined below (required)
"feast": autocomplete.ModelSelect2(url="feast-autocomplete"),
"office": autocomplete.ModelSelect2(url="office-autocomplete"),
"service": autocomplete.ModelSelect2(url="service-autocomplete"),
"genre": autocomplete.ModelSelect2(url="genre-autocomplete"),
"position": TextInputWidget(),
"cantus_id": TextInputWidget(),
Expand Down Expand Up @@ -591,10 +591,10 @@ class Meta:
label="Sequence",
)

# We use NameModelChoiceField here so the dropdown list of office/mass displays the name
# We use NameModelChoiceField here so the dropdown list of service/mass displays the name
# instead of [name] + description
office = NameModelChoiceField(
queryset=Office.objects.all().order_by("name"),
service = NameModelChoiceField(
queryset=Service.objects.all().order_by("name"),
required=False,
)
# We use NameModelChoiceField here so the dropdown list of genres displays the name
Expand Down Expand Up @@ -639,9 +639,9 @@ class Meta:
name.widget.attrs.update({"style": "width: 400px;"})


class AdminOfficeForm(forms.ModelForm):
class AdminServiceForm(forms.ModelForm):
class Meta:
model = Office
model = Service
fields = "__all__"

name = forms.CharField(required=True, widget=TextInputWidget)
Expand Down Expand Up @@ -678,10 +678,10 @@ class Meta:
"chant_range": VolpianoAreaWidget(),
}

# We use NameModelChoiceField here so the dropdown list of office/mass displays the name
# We use NameModelChoiceField here so the dropdown list of service/mass displays the name
# instead of [name] + description
office = NameModelChoiceField(
queryset=Office.objects.all().order_by("name"),
service = NameModelChoiceField(
queryset=Service.objects.all().order_by("name"),
required=False,
)
# We use NameModelChoiceField here so the dropdown list of genres displays the name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_concordances() -> list[dict]:
"source",
"feast",
"genre",
"office",
"service",
).values(
"id",
"source_id",
Expand All @@ -72,7 +72,7 @@ def get_concordances() -> list[dict]:
"incipit",
"feast__name",
"genre__name",
"office__name",
"service__name",
"position",
"cantus_id",
"image_link",
Expand Down Expand Up @@ -112,7 +112,7 @@ def make_chant_dict(chant: dict) -> dict:
"incipit": chant["incipit"],
"feast": chant["feast__name"],
"genre": chant["genre__name"],
"office": chant["office__name"],
"service": chant["service__name"],
"position": chant["position"],
"cantus_id": chant["cantus_id"],
"image": chant["image_link"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.11 on 2024-08-07 17:10

from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("main_app", "0026_source_segment_m2m"),
]

operations = [
migrations.RenameModel(
old_name="Office",
new_name="Service",
),
migrations.RenameField(
model_name="chant",
old_name="office",
new_name="service",
),
migrations.RenameField(
model_name="sequence",
old_name="office",
new_name="service",
),
]
2 changes: 1 addition & 1 deletion django/cantusdb_project/main_app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from main_app.models.feast import Feast
from main_app.models.genre import Genre
from main_app.models.notation import Notation
from main_app.models.office import Office
from main_app.models.service import Service
from main_app.models.provenance import Provenance
from main_app.models.segment import Segment
from main_app.models.sequence import Sequence
Expand Down
4 changes: 2 additions & 2 deletions django/cantusdb_project/main_app/models/base_chant.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class Meta:
image_link = models.URLField(blank=True, null=True)
json_info = models.JSONField(null=True, blank=True)
marginalia = models.CharField(max_length=63, null=True, blank=True)
office = models.ForeignKey(
"Office", on_delete=models.PROTECT, null=True, blank=True
service = models.ForeignKey(
"Service", on_delete=models.PROTECT, null=True, blank=True
)
position = models.CharField(max_length=63, null=True, blank=True)

Expand Down
4 changes: 2 additions & 2 deletions django/cantusdb_project/main_app/models/chant.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index_components(self) -> dict:
source = self.source.title if self.source else None
genre = self.genre.name if self.genre else None
feast = self.feast.name if self.feast else None
office = self.office.name if self.office else None
service = self.service.name if self.service else None
return {
"A": (
" ".join(
Expand All @@ -38,7 +38,7 @@ def index_components(self) -> dict:
)
)
),
"B": (" ".join(filter(None, [genre, feast, office]))),
"B": (" ".join(filter(None, [genre, feast, service]))),
}

def related_chants_by_cantus_id(self) -> QuerySet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from main_app.models import BaseModel


class Office(BaseModel):
class Service(BaseModel):
name = models.CharField(max_length=3)
description = models.TextField()

Expand Down
4 changes: 2 additions & 2 deletions django/cantusdb_project/main_app/templates/browse_chants.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ <h3>Browse Chants</h3>
{% 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>
{% if chant.service %}
<a href="{% url 'service-detail' chant.service.id %}" title="{{ chant.service.description }}">{{ chant.service.name|default:"" }}</a>
{% endif %}
</td>
<td class="text-wrap" style="text-align:center">
Expand Down
6 changes: 3 additions & 3 deletions django/cantusdb_project/main_app/templates/chant_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ <h3>Create Chant</h3>

<div class="form-row">
<div class="form-group m-1 col-lg-2">
<label for="{{ form.office.id_for_label }}"><small>Service:</small></label>
<br>{{ form.office }}
<a href="/description/#Office"><small>?</small></a>
<label for="{{ form.service.id_for_label }}"><small>Service:</small></label>
<br>{{ form.service }}
<a href="/description/#Service"><small>?</small></a>
</div>
</div>

Expand Down
16 changes: 8 additions & 8 deletions django/cantusdb_project/main_app/templates/chant_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ <h3>{{ chant.incipit }}</h3>
</div>
{% endif %}

{% if chant.office %}
{% if chant.service %}
<div class="form-group col-lg-2 col-sm-6 col-6">
<dt>Service</dt>
<dd>
<a href="{% url 'office-detail' chant.office.id %}" title="{{ chant.office.description }}">{{ chant.office.name }}</a>
<a href="{% url 'service-detail' chant.service.id %}" title="{{ chant.service.description }}">{{ chant.service.name }}</a>
</dd>
</div>
{% endif %}
Expand Down Expand Up @@ -351,8 +351,8 @@ <h4>List of melodies</h4>
{{ chant.c_sequence }}
</td>
<td>
<span title="{{ chant.office.description }}">
{{ chant.office.name|default_if_none:"" }}
<span title="{{ chant.service.description }}">
{{ chant.service.name|default_if_none:"" }}
</span>
<b title="{{ chant.genre.description }}">{{ chant.genre.name|default_if_none:"" }}</b>
{{ chant.position|default_if_none:"" }}
Expand Down Expand Up @@ -385,8 +385,8 @@ <h4>List of melodies</h4>
{{ chant.c_sequence }}
</td>
<td>
<span title="{{ chant.office.description }}">
{{ chant.office.name|default_if_none:"" }}
<span title="{{ chant.service.description }}">
{{ chant.service.name|default_if_none:"" }}
</span>
<b title="{{ chant.genre.description }}">{{ chant.genre.name|default_if_none:"" }}</b>
{{ chant.position|default_if_none:"" }}
Expand Down Expand Up @@ -424,8 +424,8 @@ <h4>List of melodies</h4>
{{ chant.c_sequence }}
</td>
<td>
<span title="{{ chant.office.description }}">
{{ chant.office.name|default_if_none:"" }}
<span title="{{ chant.service.description }}">
{{ chant.service.name|default_if_none:"" }}
</span>
<b title="{{ chant.genre.description }}">{{ chant.genre.name|default_if_none:"" }}</b>
{{ chant.position|default_if_none:"" }}
Expand Down
Loading

0 comments on commit 40391a9

Please sign in to comment.