diff --git a/django/cantusdb_project/main_app/admin/source.py b/django/cantusdb_project/main_app/admin/source.py index 0bc8d6c4f..79818d5d2 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 = ( @@ -28,6 +37,8 @@ class SourceAdmin(BaseModelAdmin): "holding_institution__migrated_identifier", "id", "provenance_notes", + "name", + "identifiers__identifier" ) 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/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.py b/django/cantusdb_project/main_app/models/source.py index 919fbac20..98caddc06 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, @@ -171,8 +177,12 @@ 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) + + if not self.full_source: + title.append("(fragment)") + return " ".join(title) 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] 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 @@