From 329d8f4cd5312296140646c294e243e8ec37bc9a Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Fri, 13 Sep 2024 16:25:07 +0200 Subject: [PATCH 1/5] Fixed: Add name field to source models Allows for the description of colloquial names for sources --- .../cantusdb_project/main_app/admin/source.py | 1 + django/cantusdb_project/main_app/forms.py | 27 ++++++++++-------- ...0032_source_name_alter_source_shelfmark.py | 28 +++++++++++++++++++ .../main_app/models/source.py | 6 ++++ 4 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 django/cantusdb_project/main_app/migrations/0032_source_name_alter_source_shelfmark.py diff --git a/django/cantusdb_project/main_app/admin/source.py b/django/cantusdb_project/main_app/admin/source.py index 0bc8d6c4f..952cd54f9 100644 --- a/django/cantusdb_project/main_app/admin/source.py +++ b/django/cantusdb_project/main_app/admin/source.py @@ -28,6 +28,7 @@ class SourceAdmin(BaseModelAdmin): "holding_institution__migrated_identifier", "id", "provenance_notes", + "name", ) readonly_fields = ( ("title", "siglum") diff --git a/django/cantusdb_project/main_app/forms.py b/django/cantusdb_project/main_app/forms.py index 81dce3c75..4f65fa883 100644 --- a/django/cantusdb_project/main_app/forms.py +++ b/django/cantusdb_project/main_app/forms.py @@ -720,22 +720,27 @@ class Meta: model = Source fields = "__all__" - title = forms.CharField( - required=True, - widget=TextInputWidget, - help_text="Full Source Identification (City, Archive, Shelf-mark)", - ) - title.widget.attrs.update({"style": "width: 610px;"}) + # title = forms.CharField( + # required=True, + # widget=TextInputWidget, + # help_text="Full Source Identification (City, Archive, Shelf-mark)", + # ) + # title.widget.attrs.update({"style": "width: 610px;"}) + # + # siglum = forms.CharField( + # required=True, + # widget=TextInputWidget, + # help_text="RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).", + # ) - siglum = forms.CharField( + shelfmark = forms.CharField( required=True, widget=TextInputWidget, - help_text="RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).", ) - shelfmark = forms.CharField( - required=True, - widget=TextInputWidget, + name = forms.CharField( + required=False, + widget=TextInputWidget ) holding_institution = forms.ModelChoiceField( diff --git a/django/cantusdb_project/main_app/migrations/0032_source_name_alter_source_shelfmark.py b/django/cantusdb_project/main_app/migrations/0032_source_name_alter_source_shelfmark.py new file mode 100644 index 000000000..12a3e2327 --- /dev/null +++ b/django/cantusdb_project/main_app/migrations/0032_source_name_alter_source_shelfmark.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.14 on 2024-09-13 14:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("main_app", "0031_alter_source_holding_institution_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="source", + name="name", + field=models.CharField( + blank=True, + help_text="A colloquial or commonly-used name for the source", + max_length=255, + null=True, + ), + ), + migrations.AlterField( + model_name="source", + name="shelfmark", + field=models.CharField(max_length=255), + ), + ] diff --git a/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py index 919fbac20..297c3f087 100644 --- a/django/cantusdb_project/main_app/models/source.py +++ b/django/cantusdb_project/main_app/models/source.py @@ -50,6 +50,12 @@ class Source(BaseModel): blank=False, null=False, ) + name = models.CharField( + max_length=255, + blank=True, + null=True, + help_text="A colloquial or commonly-used name for the source" + ) provenance = models.ForeignKey( "Provenance", on_delete=models.PROTECT, From 61a2d31c868a286a7cc00c57659188ac7d73260d Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Fri, 13 Sep 2024 16:41:07 +0200 Subject: [PATCH 2/5] New: Add Source Identifier field Allows for the capture of other identifiers for a source. --- .../cantusdb_project/main_app/admin/source.py | 11 +++- .../migrations/0033_sourceidentifier.py | 53 +++++++++++++++++++ .../main_app/models/__init__.py | 1 + .../main_app/models/source_identifier.py | 33 ++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 django/cantusdb_project/main_app/migrations/0033_sourceidentifier.py create mode 100644 django/cantusdb_project/main_app/models/source_identifier.py diff --git a/django/cantusdb_project/main_app/admin/source.py b/django/cantusdb_project/main_app/admin/source.py index 952cd54f9..ebcfba82c 100644 --- a/django/cantusdb_project/main_app/admin/source.py +++ b/django/cantusdb_project/main_app/admin/source.py @@ -3,7 +3,7 @@ from main_app.admin.base_admin import BaseModelAdmin, EXCLUDE, READ_ONLY from main_app.admin.filters import InputFilter from main_app.forms import AdminSourceForm -from main_app.models import Source +from main_app.models import Source, SourceIdentifier class SourceKeyFilter(InputFilter): @@ -15,10 +15,19 @@ def queryset(self, request, queryset): return queryset.filter(holding_institution__siglum__icontains=self.value()) +class IdentifiersInline(admin.TabularInline): + model = SourceIdentifier + extra = 0 + + def get_queryset(self, request): + return super().get_queryset(request).select_related("source__holding_institution") + + @admin.register(Source) class SourceAdmin(BaseModelAdmin): exclude = EXCLUDE + ("source_status",) raw_id_fields = ("holding_institution",) + inlines = (IdentifiersInline,) # These search fields are also available on the user-source inline relationship in the user admin page search_fields = ( diff --git a/django/cantusdb_project/main_app/migrations/0033_sourceidentifier.py b/django/cantusdb_project/main_app/migrations/0033_sourceidentifier.py new file mode 100644 index 000000000..d17e23cb0 --- /dev/null +++ b/django/cantusdb_project/main_app/migrations/0033_sourceidentifier.py @@ -0,0 +1,53 @@ +# Generated by Django 4.2.14 on 2024-09-13 14:34 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("main_app", "0032_source_name_alter_source_shelfmark"), + ] + + operations = [ + migrations.CreateModel( + name="SourceIdentifier", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("identifier", models.CharField(max_length=255)), + ( + "type", + models.IntegerField( + choices=[ + (1, "Other catalogues"), + (2, "olim (Former shelfmark)"), + (3, "Alternative names"), + (4, "RISM Online"), + ] + ), + ), + ("note", models.TextField(blank=True, null=True)), + ( + "source", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="identifiers", + to="main_app.source", + ), + ), + ], + options={ + "verbose_name": "Source Identifier", + "ordering": ("type",), + }, + ), + ] diff --git a/django/cantusdb_project/main_app/models/__init__.py b/django/cantusdb_project/main_app/models/__init__.py index ea1149eca..5ed2a4227 100644 --- a/django/cantusdb_project/main_app/models/__init__.py +++ b/django/cantusdb_project/main_app/models/__init__.py @@ -10,6 +10,7 @@ from main_app.models.segment import Segment from main_app.models.sequence import Sequence from main_app.models.source import Source +from main_app.models.source_identifier import SourceIdentifier from main_app.models.institution import Institution from main_app.models.institution_identifier import InstitutionIdentifier from main_app.models.project import Project diff --git a/django/cantusdb_project/main_app/models/source_identifier.py b/django/cantusdb_project/main_app/models/source_identifier.py new file mode 100644 index 000000000..85ccb5f71 --- /dev/null +++ b/django/cantusdb_project/main_app/models/source_identifier.py @@ -0,0 +1,33 @@ +from django.db import models + +class SourceIdentifier(models.Model): + class Meta: + verbose_name = "Source Identifier" + ordering = ('type',) + + OTHER = 1 + OLIM = 2 + ALTN = 3 + RISM_ONLINE = 4 + + IDENTIFIER_TYPES = ( + (OTHER, 'Other catalogues'), + (OLIM, 'olim (Former shelfmark)'), + (ALTN, 'Alternative names'), + (RISM_ONLINE, "RISM Online") + ) + + identifier = models.CharField(max_length=255) + type = models.IntegerField(choices=IDENTIFIER_TYPES) + note = models.TextField(blank=True, null=True) + source = models.ForeignKey("Source", + related_name="identifiers", + on_delete=models.CASCADE) + + def __str__(self): + return f"{self.identifier}" + + @property + def identifier_type(self): + d = dict(self.IDENTIFIER_TYPES) + return d[self.type] From fe72a2f164b2675dc9e69d68936d8920f2cd61f7 Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Fri, 13 Sep 2024 16:41:27 +0200 Subject: [PATCH 3/5] Fixed: Change "Private" to "Cantus" --- django/cantusdb_project/main_app/models/source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py index 297c3f087..a8f2cd19a 100644 --- a/django/cantusdb_project/main_app/models/source.py +++ b/django/cantusdb_project/main_app/models/source.py @@ -177,7 +177,7 @@ def short_heading(self) -> str: if holdinst.siglum and holdinst.siglum != "XX-NN": title.append(f"{holdinst.siglum}") elif holdinst.is_private_collector: - title.append("Private") + title.append("Cantus") tt = self.shelfmark if self.shelfmark else self.title title.append(tt) From d0f7bf5b232e4d56621107dbf19885785cb670f1 Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Fri, 13 Sep 2024 16:43:42 +0200 Subject: [PATCH 4/5] Fixed: Ensure the source identifiers are searchable in the admin UI --- django/cantusdb_project/main_app/admin/source.py | 1 + 1 file changed, 1 insertion(+) diff --git a/django/cantusdb_project/main_app/admin/source.py b/django/cantusdb_project/main_app/admin/source.py index ebcfba82c..79818d5d2 100644 --- a/django/cantusdb_project/main_app/admin/source.py +++ b/django/cantusdb_project/main_app/admin/source.py @@ -38,6 +38,7 @@ class SourceAdmin(BaseModelAdmin): "id", "provenance_notes", "name", + "identifiers__identifier" ) readonly_fields = ( ("title", "siglum") From b407110118d5a7ac73c409454c182477820717bc Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Fri, 13 Sep 2024 17:18:41 +0200 Subject: [PATCH 5/5] Fixed: Adjust display fields --- django/cantusdb_project/main_app/models/source.py | 4 ++++ django/cantusdb_project/main_app/templates/source_detail.html | 2 +- django/cantusdb_project/main_app/templates/source_list.html | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py index a8f2cd19a..98caddc06 100644 --- a/django/cantusdb_project/main_app/models/source.py +++ b/django/cantusdb_project/main_app/models/source.py @@ -181,4 +181,8 @@ def short_heading(self) -> str: tt = self.shelfmark if self.shelfmark else self.title title.append(tt) + + if not self.full_source: + title.append("(fragment)") + return " ".join(title) diff --git a/django/cantusdb_project/main_app/templates/source_detail.html b/django/cantusdb_project/main_app/templates/source_detail.html index 357f5dc46..a7eab6478 100644 --- a/django/cantusdb_project/main_app/templates/source_detail.html +++ b/django/cantusdb_project/main_app/templates/source_detail.html @@ -35,7 +35,7 @@

{{ source.heading }}

{% if source.holding_institution %} -
Siglum
+
Cantus Siglum
{{ source.short_heading }}
Holding Institution
diff --git a/django/cantusdb_project/main_app/templates/source_list.html b/django/cantusdb_project/main_app/templates/source_list.html index a65800af0..66bb2e78f 100644 --- a/django/cantusdb_project/main_app/templates/source_list.html +++ b/django/cantusdb_project/main_app/templates/source_list.html @@ -88,8 +88,8 @@

Browse Sources

{% sortable_header request "country" %} - {% sortable_header request "city_institution" "City + Institution" %} - {% sortable_header request "source" "Source" %} + {% sortable_header request "city_institution" "City + Holding Institution" %} + {% sortable_header request "source" "Cantus Siglum" %} Summary Date/Origin Image Link