From bea8ded5a495fc6fd1a45d2c7683f558235bb1be Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Thu, 6 Jun 2024 15:34:34 +0200 Subject: [PATCH 1/6] Fixed: Add institution models - alters the source model for storing a reference to the holding institution - Adds the institution identifiers models Fixes #1505 --- .../cantusdb_project/main_app/identifiers.py | 26 ++++++ .../main_app/migrations/0013_institution.py | 67 ++++++++++++++ .../migrations/0014_institutionidentifier.py | 92 +++++++++++++++++++ .../0015_source_holding_institution.py | 24 +++++ .../main_app/models/__init__.py | 2 + .../main_app/models/institution.py | 12 +++ .../main_app/models/institution_identifier.py | 12 +++ .../main_app/models/source.py | 6 ++ 8 files changed, 241 insertions(+) create mode 100644 django/cantusdb_project/main_app/identifiers.py create mode 100644 django/cantusdb_project/main_app/migrations/0013_institution.py create mode 100644 django/cantusdb_project/main_app/migrations/0014_institutionidentifier.py create mode 100644 django/cantusdb_project/main_app/migrations/0015_source_holding_institution.py create mode 100644 django/cantusdb_project/main_app/models/institution.py create mode 100644 django/cantusdb_project/main_app/models/institution_identifier.py diff --git a/django/cantusdb_project/main_app/identifiers.py b/django/cantusdb_project/main_app/identifiers.py new file mode 100644 index 000000000..844ddcc50 --- /dev/null +++ b/django/cantusdb_project/main_app/identifiers.py @@ -0,0 +1,26 @@ +class ExternalIdentifiers: + RISM = 1 + VIAF = 2 + WIKIDATA = 3 + GND = 4 + BNF = 5 + LC = 6 + + +IDENTIFIER_TYPES = ( + (ExternalIdentifiers.RISM, "RISM Online"), + (ExternalIdentifiers.VIAF, "VIAF"), + (ExternalIdentifiers.WIKIDATA, "Wikidata"), + (ExternalIdentifiers.GND, "GND (Gemeinsame Normdatei)"), + (ExternalIdentifiers.BNF, "Bibliothèque national de France"), + (ExternalIdentifiers.LC, "Library of Congress") +) + +TYPE_PREFIX = { + ExternalIdentifiers.RISM: ("rism", "https://rism.online/"), + ExternalIdentifiers.VIAF: ("viaf", "https://viaf.org/viaf/"), + ExternalIdentifiers.WIKIDATA: ("wkp", "https://www.wikidata.org/wiki/"), + ExternalIdentifiers.GND: ("dnb", "https://d-nb.info/gnd/"), + ExternalIdentifiers.BNF: ("bnf", "https://catalogue.bnf.fr/ark:/12148/cb"), + ExternalIdentifiers.LC: ("lc", "https://id.loc.gov/authorities/") +} diff --git a/django/cantusdb_project/main_app/migrations/0013_institution.py b/django/cantusdb_project/main_app/migrations/0013_institution.py new file mode 100644 index 000000000..b206c5342 --- /dev/null +++ b/django/cantusdb_project/main_app/migrations/0013_institution.py @@ -0,0 +1,67 @@ +# Generated by Django 4.1.6 on 2024-06-06 12:06 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("main_app", "0012_alter_source_date_alter_source_title"), + ] + + operations = [ + migrations.CreateModel( + name="Institution", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "date_created", + models.DateTimeField( + auto_now_add=True, help_text="The date this entry was created" + ), + ), + ( + "date_updated", + models.DateTimeField( + auto_now=True, help_text="The date this entry was updated" + ), + ), + ("name", models.CharField(default="s.n.", max_length=255)), + ("siglum", models.CharField(default="XX-Nn", max_length=32)), + ("city", models.CharField(blank=True, max_length=64, null=True)), + ( + "created_by", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="%(class)s_created_by_user", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "last_updated_by", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="%(class)s_last_updated_by_user", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "abstract": False, + }, + ), + ] diff --git a/django/cantusdb_project/main_app/migrations/0014_institutionidentifier.py b/django/cantusdb_project/main_app/migrations/0014_institutionidentifier.py new file mode 100644 index 000000000..f544fd859 --- /dev/null +++ b/django/cantusdb_project/main_app/migrations/0014_institutionidentifier.py @@ -0,0 +1,92 @@ +# Generated by Django 4.1.6 on 2024-06-06 12:16 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("main_app", "0013_institution"), + ] + + operations = [ + migrations.CreateModel( + name="InstitutionIdentifier", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "date_created", + models.DateTimeField( + auto_now_add=True, help_text="The date this entry was created" + ), + ), + ( + "date_updated", + models.DateTimeField( + auto_now=True, help_text="The date this entry was updated" + ), + ), + ( + "identifier", + models.CharField( + help_text="Do not provide the full URL here; only the identifier.", + max_length=512, + ), + ), + ( + "identifier_type", + models.IntegerField( + choices=[ + (1, "RISM Online"), + (2, "VIAF"), + (3, "Wikidata"), + (4, "GND (Gemeinsame Normdatei)"), + (5, "Bibliothèque national de France"), + (6, "Library of Congress"), + ] + ), + ), + ( + "created_by", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="%(class)s_created_by_user", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "institution", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="identifiers", + to="main_app.institution", + ), + ), + ( + "last_updated_by", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="%(class)s_last_updated_by_user", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "abstract": False, + }, + ), + ] diff --git a/django/cantusdb_project/main_app/migrations/0015_source_holding_institution.py b/django/cantusdb_project/main_app/migrations/0015_source_holding_institution.py new file mode 100644 index 000000000..2de78ae33 --- /dev/null +++ b/django/cantusdb_project/main_app/migrations/0015_source_holding_institution.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.11 on 2024-06-06 13:05 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("main_app", "0014_institutionidentifier"), + ] + + operations = [ + migrations.AddField( + model_name="source", + name="holding_institution", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="main_app.institution", + ), + ), + ] diff --git a/django/cantusdb_project/main_app/models/__init__.py b/django/cantusdb_project/main_app/models/__init__.py index 67d135611..fad179093 100644 --- a/django/cantusdb_project/main_app/models/__init__.py +++ b/django/cantusdb_project/main_app/models/__init__.py @@ -11,3 +11,5 @@ from main_app.models.sequence import Sequence from main_app.models.rism_siglum import RismSiglum from main_app.models.source import Source +from main_app.models.institution import Institution +from main_app.models.institution_identifier import InstitutionIdentifier \ No newline at end of file diff --git a/django/cantusdb_project/main_app/models/institution.py b/django/cantusdb_project/main_app/models/institution.py new file mode 100644 index 000000000..f8b85c522 --- /dev/null +++ b/django/cantusdb_project/main_app/models/institution.py @@ -0,0 +1,12 @@ +from django.db import models + +from main_app.models import BaseModel + + +class Institution(BaseModel): + name = models.CharField(max_length=255, default="s.n.") + siglum = models.CharField(max_length=32, default="XX-Nn") + city = models.CharField(max_length=64, blank=True, null=True) + + def __str__(self): + return f"{self.name} ({self.siglum})" diff --git a/django/cantusdb_project/main_app/models/institution_identifier.py b/django/cantusdb_project/main_app/models/institution_identifier.py new file mode 100644 index 000000000..51da6e920 --- /dev/null +++ b/django/cantusdb_project/main_app/models/institution_identifier.py @@ -0,0 +1,12 @@ +from django.db import models + +from main_app.identifiers import IDENTIFIER_TYPES +from main_app.models import BaseModel + + +class InstitutionIdentifier(BaseModel): + identifier = models.CharField(max_length=512, help_text="Do not provide the full URL here; only the identifier.") + identifier_type = models.IntegerField(choices=IDENTIFIER_TYPES) + institution = models.ForeignKey("Institution", + related_name="identifiers", + on_delete=models.CASCADE) diff --git a/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py index 6d0efe68b..e49363306 100644 --- a/django/cantusdb_project/main_app/models/source.py +++ b/django/cantusdb_project/main_app/models/source.py @@ -44,6 +44,12 @@ class Source(BaseModel): null=True, blank=True, ) + holding_institution = models.ForeignKey( + "Institution", + on_delete=models.PROTECT, + null=True, + blank=True, + ) provenance = models.ForeignKey( "Provenance", on_delete=models.PROTECT, From 44623599f500425fa84bc744929976468f24fa9b Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Thu, 6 Jun 2024 16:05:32 +0200 Subject: [PATCH 2/6] Fixed: Add institutions to the new admin layout Also runs black on the files to make them fit the formatting --- django/cantusdb_project/main_app/admin/__init__.py | 2 ++ django/cantusdb_project/main_app/admin/institution.py | 6 +++++- .../main_app/admin/institution_identifier.py | 6 +++++- django/cantusdb_project/main_app/identifiers.py | 4 ++-- django/cantusdb_project/main_app/models/__init__.py | 2 +- .../main_app/models/institution_identifier.py | 11 +++++++---- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/django/cantusdb_project/main_app/admin/__init__.py b/django/cantusdb_project/main_app/admin/__init__.py index 15f8792fb..6839ad2d8 100644 --- a/django/cantusdb_project/main_app/admin/__init__.py +++ b/django/cantusdb_project/main_app/admin/__init__.py @@ -10,3 +10,5 @@ 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 diff --git a/django/cantusdb_project/main_app/admin/institution.py b/django/cantusdb_project/main_app/admin/institution.py index f1523a262..99cb914b1 100644 --- a/django/cantusdb_project/main_app/admin/institution.py +++ b/django/cantusdb_project/main_app/admin/institution.py @@ -1,5 +1,9 @@ from django.contrib import admin +from main_app.admin.base_admin import BaseModelAdmin +from main_app.models import Institution -class InstitutionAdmin(admin.ModelAdmin): + +@admin.register(Institution) +class InstitutionAdmin(BaseModelAdmin): pass diff --git a/django/cantusdb_project/main_app/admin/institution_identifier.py b/django/cantusdb_project/main_app/admin/institution_identifier.py index f0d89c07b..eacc06c0f 100644 --- a/django/cantusdb_project/main_app/admin/institution_identifier.py +++ b/django/cantusdb_project/main_app/admin/institution_identifier.py @@ -1,5 +1,9 @@ from django.contrib import admin +from main_app.admin.base_admin import BaseModelAdmin +from main_app.models import InstitutionIdentifier -class InstitutionIdentifierAdmin(admin.ModelAdmin): + +@admin.register(InstitutionIdentifier) +class InstitutionIdentifierAdmin(BaseModelAdmin): pass diff --git a/django/cantusdb_project/main_app/identifiers.py b/django/cantusdb_project/main_app/identifiers.py index 844ddcc50..4ab27e298 100644 --- a/django/cantusdb_project/main_app/identifiers.py +++ b/django/cantusdb_project/main_app/identifiers.py @@ -13,7 +13,7 @@ class ExternalIdentifiers: (ExternalIdentifiers.WIKIDATA, "Wikidata"), (ExternalIdentifiers.GND, "GND (Gemeinsame Normdatei)"), (ExternalIdentifiers.BNF, "Bibliothèque national de France"), - (ExternalIdentifiers.LC, "Library of Congress") + (ExternalIdentifiers.LC, "Library of Congress"), ) TYPE_PREFIX = { @@ -22,5 +22,5 @@ class ExternalIdentifiers: ExternalIdentifiers.WIKIDATA: ("wkp", "https://www.wikidata.org/wiki/"), ExternalIdentifiers.GND: ("dnb", "https://d-nb.info/gnd/"), ExternalIdentifiers.BNF: ("bnf", "https://catalogue.bnf.fr/ark:/12148/cb"), - ExternalIdentifiers.LC: ("lc", "https://id.loc.gov/authorities/") + ExternalIdentifiers.LC: ("lc", "https://id.loc.gov/authorities/"), } diff --git a/django/cantusdb_project/main_app/models/__init__.py b/django/cantusdb_project/main_app/models/__init__.py index fad179093..9959354e9 100644 --- a/django/cantusdb_project/main_app/models/__init__.py +++ b/django/cantusdb_project/main_app/models/__init__.py @@ -12,4 +12,4 @@ from main_app.models.rism_siglum import RismSiglum from main_app.models.source import Source from main_app.models.institution import Institution -from main_app.models.institution_identifier import InstitutionIdentifier \ No newline at end of file +from main_app.models.institution_identifier import InstitutionIdentifier diff --git a/django/cantusdb_project/main_app/models/institution_identifier.py b/django/cantusdb_project/main_app/models/institution_identifier.py index 51da6e920..9ca13d537 100644 --- a/django/cantusdb_project/main_app/models/institution_identifier.py +++ b/django/cantusdb_project/main_app/models/institution_identifier.py @@ -5,8 +5,11 @@ class InstitutionIdentifier(BaseModel): - identifier = models.CharField(max_length=512, help_text="Do not provide the full URL here; only the identifier.") + identifier = models.CharField( + max_length=512, + help_text="Do not provide the full URL here; only the identifier.", + ) identifier_type = models.IntegerField(choices=IDENTIFIER_TYPES) - institution = models.ForeignKey("Institution", - related_name="identifiers", - on_delete=models.CASCADE) + institution = models.ForeignKey( + "Institution", related_name="identifiers", on_delete=models.CASCADE + ) From 75cf1560443783d29c8014f088ab9c857158459d Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Tue, 11 Jun 2024 15:44:25 +0200 Subject: [PATCH 3/6] Fixed: Expand institution model After a review of the existing institution information in Cantus, the following improvements are made - Adds region, country, and alternate names fields for the institution - Modifies the admin site for institutions to show the table, and to show an inline for adding identifiers --- .../main_app/admin/institution.py | 21 +++++++- ...titution_country_alter_institution_city.py | 51 +++++++++++++++++++ .../main_app/models/institution.py | 22 ++++++-- 3 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 django/cantusdb_project/main_app/migrations/0016_institution_alternate_names_institution_region_squashed_0017_institution_country_alter_institution_city.py diff --git a/django/cantusdb_project/main_app/admin/institution.py b/django/cantusdb_project/main_app/admin/institution.py index 99cb914b1..e93333d01 100644 --- a/django/cantusdb_project/main_app/admin/institution.py +++ b/django/cantusdb_project/main_app/admin/institution.py @@ -1,9 +1,26 @@ from django.contrib import admin from main_app.admin.base_admin import BaseModelAdmin -from main_app.models import Institution +from main_app.models import Institution, InstitutionIdentifier + + +class InstitutionIdentifierInline(admin.TabularInline): + model = InstitutionIdentifier + extra = 0 + exclude = ["created_by", "last_updated_by"] @admin.register(Institution) class InstitutionAdmin(BaseModelAdmin): - pass + list_display = ("name", "siglum", "get_city_region", "country") + search_fields = ("name", "siglum", "city", "region", "alternate_names") + list_filter = ("city",) + inlines = (InstitutionIdentifierInline,) + + def get_city_region(self, obj): + name = [obj.city] + if obj.region: + name.append(f"({obj.region})") + return " ".join(name) + + get_city_region.short_description = "City" diff --git a/django/cantusdb_project/main_app/migrations/0016_institution_alternate_names_institution_region_squashed_0017_institution_country_alter_institution_city.py b/django/cantusdb_project/main_app/migrations/0016_institution_alternate_names_institution_region_squashed_0017_institution_country_alter_institution_city.py new file mode 100644 index 000000000..15e17ec59 --- /dev/null +++ b/django/cantusdb_project/main_app/migrations/0016_institution_alternate_names_institution_region_squashed_0017_institution_country_alter_institution_city.py @@ -0,0 +1,51 @@ +# Generated by Django 4.1.6 on 2024-06-11 09:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + replaces = [ + ("main_app", "0016_institution_alternate_names_institution_region"), + ("main_app", "0017_institution_country_alter_institution_city"), + ] + + dependencies = [ + ("main_app", "0015_source_holding_institution"), + ] + + operations = [ + migrations.AddField( + model_name="institution", + name="alternate_names", + field=models.TextField( + blank=True, + help_text="Enter alternate names on separate lines.", + null=True, + ), + ), + migrations.AddField( + model_name="institution", + name="region", + field=models.CharField( + blank=True, + help_text='Province / State / Canton / County. Used to disambiguate cities, e.g., "London (Ontario)".', + max_length=64, + null=True, + ), + ), + migrations.AddField( + model_name="institution", + name="country", + field=models.CharField(default="s.l.", max_length=64), + ), + migrations.AlterField( + model_name="institution", + name="city", + field=models.CharField( + blank=True, + help_text="City / Town / Village / Settlement", + max_length=64, + null=True, + ), + ), + ] diff --git a/django/cantusdb_project/main_app/models/institution.py b/django/cantusdb_project/main_app/models/institution.py index f8b85c522..b8f11ca10 100644 --- a/django/cantusdb_project/main_app/models/institution.py +++ b/django/cantusdb_project/main_app/models/institution.py @@ -3,10 +3,26 @@ from main_app.models import BaseModel +region_help_text = """Province / State / Canton / County. Used to disambiguate cities, e.g., "London (Ontario)".""" +city_help_text = """City / Town / Village / Settlement""" + + class Institution(BaseModel): name = models.CharField(max_length=255, default="s.n.") siglum = models.CharField(max_length=32, default="XX-Nn") - city = models.CharField(max_length=64, blank=True, null=True) + city = models.CharField( + max_length=64, blank=True, null=True, help_text=city_help_text + ) + region = models.CharField( + max_length=64, blank=True, null=True, help_text=region_help_text + ) + country = models.CharField(max_length=64, default="s.l.") + alternate_names = models.TextField( + blank=True, null=True, help_text="Enter alternate names on separate lines." + ) - def __str__(self): - return f"{self.name} ({self.siglum})" + def __str__(self) -> str: + names: list = [self.name] + if self.siglum: + names.append(f"({self.siglum})") + return " ".join(names) From 5d9998bc6f207eed6e97595eeb729b8d91008bfc Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Tue, 11 Jun 2024 17:02:17 +0200 Subject: [PATCH 4/6] Add former sigla to institution records Request from Debra for institution records --- .../0018_institution_former_sigla.py | 22 +++++++++++++++++++ .../main_app/models/institution.py | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 django/cantusdb_project/main_app/migrations/0018_institution_former_sigla.py diff --git a/django/cantusdb_project/main_app/migrations/0018_institution_former_sigla.py b/django/cantusdb_project/main_app/migrations/0018_institution_former_sigla.py new file mode 100644 index 000000000..cdd13afe9 --- /dev/null +++ b/django/cantusdb_project/main_app/migrations/0018_institution_former_sigla.py @@ -0,0 +1,22 @@ +# Generated by Django 4.1.6 on 2024-06-11 15:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ( + "main_app", + "0016_institution_alternate_names_institution_region_squashed_0017_institution_country_alter_institution_city", + ), + ] + + operations = [ + migrations.AddField( + model_name="institution", + name="former_sigla", + field=models.TextField( + blank=True, help_text="Enter former sigla on separate lines.", null=True + ), + ), + ] diff --git a/django/cantusdb_project/main_app/models/institution.py b/django/cantusdb_project/main_app/models/institution.py index b8f11ca10..c4a2140fa 100644 --- a/django/cantusdb_project/main_app/models/institution.py +++ b/django/cantusdb_project/main_app/models/institution.py @@ -20,6 +20,9 @@ class Institution(BaseModel): alternate_names = models.TextField( blank=True, null=True, help_text="Enter alternate names on separate lines." ) + former_sigla = models.TextField( + blank=True, null=True, help_text="Enter former sigla on separate lines." + ) def __str__(self) -> str: names: list = [self.name] From 4ac2d9173af79bed90829d67a94d2987eaa01d3a Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Wed, 12 Jun 2024 17:02:42 +0200 Subject: [PATCH 5/6] Enhance the display of the institution identifiers --- .../main_app/admin/institution_identifier.py | 3 ++- .../main_app/models/institution_identifier.py | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/django/cantusdb_project/main_app/admin/institution_identifier.py b/django/cantusdb_project/main_app/admin/institution_identifier.py index eacc06c0f..6eb1288c9 100644 --- a/django/cantusdb_project/main_app/admin/institution_identifier.py +++ b/django/cantusdb_project/main_app/admin/institution_identifier.py @@ -6,4 +6,5 @@ @admin.register(InstitutionIdentifier) class InstitutionIdentifierAdmin(BaseModelAdmin): - pass + list_display = ('identifier', 'identifier_type') + raw_id_fields = ("institution",) diff --git a/django/cantusdb_project/main_app/models/institution_identifier.py b/django/cantusdb_project/main_app/models/institution_identifier.py index 9ca13d537..6e0c4df85 100644 --- a/django/cantusdb_project/main_app/models/institution_identifier.py +++ b/django/cantusdb_project/main_app/models/institution_identifier.py @@ -1,6 +1,6 @@ from django.db import models -from main_app.identifiers import IDENTIFIER_TYPES +from main_app.identifiers import IDENTIFIER_TYPES, TYPE_PREFIX from main_app.models import BaseModel @@ -13,3 +13,21 @@ class InstitutionIdentifier(BaseModel): institution = models.ForeignKey( "Institution", related_name="identifiers", on_delete=models.CASCADE ) + + def __str__(self): + return f"{self.identifier_prefix}:{self.identifier}" + + @property + def identifier_label(self) -> str: + d: dict[int, str] = dict(IDENTIFIER_TYPES) + return d[self.identifier_type] + + @property + def identifier_prefix(self) -> str: + (pfx, _) = TYPE_PREFIX[self.identifier_type] + return pfx + + @property + def identifier_url(self) -> str: + (_, url) = TYPE_PREFIX[self.identifier_type] + return f"{url}{self.identifier}" From 5605ba644836f46f4ed57983ddae68cf40c51352 Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Thu, 13 Jun 2024 09:26:23 +0200 Subject: [PATCH 6/6] Adjust string formatting --- django/cantusdb_project/main_app/admin/institution.py | 9 ++++----- django/cantusdb_project/main_app/models/institution.py | 6 ++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/django/cantusdb_project/main_app/admin/institution.py b/django/cantusdb_project/main_app/admin/institution.py index e93333d01..71d9c9d48 100644 --- a/django/cantusdb_project/main_app/admin/institution.py +++ b/django/cantusdb_project/main_app/admin/institution.py @@ -17,10 +17,9 @@ class InstitutionAdmin(BaseModelAdmin): list_filter = ("city",) inlines = (InstitutionIdentifierInline,) - def get_city_region(self, obj): - name = [obj.city] - if obj.region: - name.append(f"({obj.region})") - return " ".join(name) + def get_city_region(self, obj) -> str: + city: str = obj.city if obj.city else "[No city]" + region: str = f"({obj.region})" if obj.region else "" + return f"{city} {region}" get_city_region.short_description = "City" diff --git a/django/cantusdb_project/main_app/models/institution.py b/django/cantusdb_project/main_app/models/institution.py index c4a2140fa..02fd1f19e 100644 --- a/django/cantusdb_project/main_app/models/institution.py +++ b/django/cantusdb_project/main_app/models/institution.py @@ -25,7 +25,5 @@ class Institution(BaseModel): ) def __str__(self) -> str: - names: list = [self.name] - if self.siglum: - names.append(f"({self.siglum})") - return " ".join(names) + sigl: str = f"({self.siglum})" if self.siglum else "" + return f"{self.name} {sigl}"