Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Institution source changes #1629

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion django/cantusdb_project/main_app/admin/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = (
Expand All @@ -28,6 +37,8 @@ class SourceAdmin(BaseModelAdmin):
"holding_institution__migrated_identifier",
"id",
"provenance_notes",
"name",
"identifiers__identifier"
)
readonly_fields = (
("title", "siglum")
Expand Down
27 changes: 16 additions & 11 deletions django/cantusdb_project/main_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
# )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we aren't planning on reintroducing these fields in the admin form (I see currently they're read only in the admin page) then we can probably remove this comment.

Is the idea that eventually we will remove title and siglum data all together?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess I’m just hedging my bets here, waiting for someone to ask “but wait, where did the siglum field go” (and then another 128 emails follow ;-)


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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
Original file line number Diff line number Diff line change
@@ -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",),
},
),
]
1 change: 1 addition & 0 deletions django/cantusdb_project/main_app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion django/cantusdb_project/main_app/models/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
33 changes: 33 additions & 0 deletions django/cantusdb_project/main_app/models/source_identifier.py
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h3>{{ source.heading }}</h3>

<dl>
{% if source.holding_institution %}
<dt>Siglum</dt>
<dt>Cantus Siglum</dt>
<dd>{{ source.short_heading }}</dd>
<dt>Holding Institution</dt>
<dd>
Expand Down
4 changes: 2 additions & 2 deletions django/cantusdb_project/main_app/templates/source_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ <h3>Browse Sources</h3>
<thead>
<tr>
{% 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" %}
<th scope="col" class="text-wrap" style="text-align:center">Summary</th>
<th scope="col" class="text-wrap" style="text-align:center">Date/Origin</th>
<th scope="col" class="text-wrap" style="text-align:center">Image Link</th>
Expand Down
Loading