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

Merge develop into staging, 22 July 2024 #1571

Merged
merged 16 commits into from
Jul 22, 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
11 changes: 9 additions & 2 deletions django/cantusdb_project/main_app/admin/chant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
@admin.register(Chant)
class ChantAdmin(BaseModelAdmin):

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

@admin.display(description="Source Siglum")
def get_source_siglum(self, obj):
if obj.source:
return obj.source.siglum
return obj.source.short_heading

list_display = (
"incipit",
Expand Down Expand Up @@ -50,4 +57,4 @@ def get_source_siglum(self, obj):
"source",
"feast",
)
ordering = ("source__siglum",)
ordering = ("source__holding_institution__siglum", "source__shelfmark")
2 changes: 1 addition & 1 deletion django/cantusdb_project/main_app/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class InputFilter(SimpleListFilter):
template = "admin/input_filter.html"

def lookups(self, request, model_admin):
return (),
return ((),)

def choices(self, changelist):
all_choice = next(super().choices(changelist))
Expand Down
28 changes: 23 additions & 5 deletions django/cantusdb_project/main_app/admin/institution.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class InstitutionSourceInline(admin.TabularInline):
can_delete = False

def link_id_field(self, obj):
change_url = reverse('admin:main_app_source_change', args=(obj.pk,))
change_url = reverse("admin:main_app_source_change", args=(obj.pk,))
return mark_safe(f'<a href="{change_url}">{obj.pk}</a>')


Expand All @@ -26,15 +26,33 @@ class InstitutionIdentifierInline(admin.TabularInline):

@admin.register(Institution)
class InstitutionAdmin(BaseModelAdmin):
list_display = ("name", "siglum", "get_city_region", "country", "is_private_collector")
list_display = (
"name",
"siglum",
"get_city_region",
"country",
"is_private_collector",
)
search_fields = ("name", "siglum", "city", "region", "alternate_names")
list_filter = ("is_private_collector", "city")
inlines = (InstitutionIdentifierInline, InstitutionSourceInline)
fieldsets = [
(None, {"fields": ("name", "city", "region", "country", "alternate_names",
"former_sigla", "private_notes")}),
(
None,
{
"fields": (
"name",
"city",
"region",
"country",
"alternate_names",
"former_sigla",
"private_notes",
)
},
),
("Private Collector", {"fields": ["is_private_collector"]}),
("Holding Institution", {"fields": ["siglum"]})
("Holding Institution", {"fields": ["siglum"]}),
]

def get_city_region(self, obj) -> str:
Expand Down
11 changes: 9 additions & 2 deletions django/cantusdb_project/main_app/admin/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@

@admin.register(Sequence)
class SequenceAdmin(BaseModelAdmin):
def get_queryset(self, request):
return (
super()
.get_queryset(request)
.select_related("source__holding_institution", "genre", "office")
)

@admin.display(description="Source Siglum")
def get_source_siglum(self, obj):
if obj.source:
return obj.source.siglum
return obj.source.short_heading

search_fields = (
"title",
Expand All @@ -34,5 +41,5 @@ def get_source_siglum(self, obj):
"feast",
)
readonly_fields = READ_ONLY + ("incipit",)
ordering = ("source__siglum",)
ordering = ("source__holding_institution__siglum", "source__shelfmark")
form = AdminSequenceForm
12 changes: 4 additions & 8 deletions django/cantusdb_project/main_app/admin/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ class SourceAdmin(BaseModelAdmin):

# These search fields are also available on the user-source inline relationship in the user admin page
search_fields = (
"siglum",
"title",
"shelfmark",
"holding_institution__siglum",
"holding_institution__name",
"id",
"provenance_notes"
"provenance_notes",
)
readonly_fields = READ_ONLY + (
readonly_fields = ("title", "siglum") + READ_ONLY + (
"number_of_chants",
"number_of_melodies",
"date_created",
Expand All @@ -52,9 +50,7 @@ class SourceAdmin(BaseModelAdmin):

list_display = (
"shelfmark",
# "title",
"holding_institution",
# "siglum",
"id",
)

Expand All @@ -68,10 +64,10 @@ class SourceAdmin(BaseModelAdmin):
"holding_institution__is_private_collector",
)

ordering = ("siglum",)
ordering = ("holding_institution__siglum", "shelfmark")

form = AdminSourceForm

def get_queryset(self, request):
queryset = super().get_queryset(request)
return queryset.select_related("holding_institution")
return queryset.select_related("holding_institution")
14 changes: 9 additions & 5 deletions django/cantusdb_project/main_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ class Meta:
widgets = {
# "title": TextInputWidget(),
# "siglum": TextInputWidget(),
"holding_institution": autocomplete.ModelSelect2(url="holding-autocomplete"),
"holding_institution": autocomplete.ModelSelect2(
url="holding-autocomplete"
),
"shelfmark": TextInputWidget(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"provenance_notes": TextInputWidget(),
Expand Down Expand Up @@ -351,7 +353,7 @@ class Meta:
project = SelectWidgetNameModelChoiceField(
queryset=Project.objects.all().order_by("id"),
help_text="Select the project (if any) that the chant belongs to.",
required = False,
required=False,
)


Expand Down Expand Up @@ -386,7 +388,9 @@ class Meta:
"other_editors",
]
widgets = {
"holding_institution": autocomplete.ModelSelect2(url="holding-autocomplete"),
"holding_institution": autocomplete.ModelSelect2(
url="holding-autocomplete"
),
"shelfmark": TextInputWidget(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"provenance_notes": TextInputWidget(),
Expand Down Expand Up @@ -453,7 +457,7 @@ class Meta:
model = Sequence
fields = [
"title",
"siglum",
# "siglum",
"incipit",
"folio",
"s_sequence",
Expand All @@ -472,7 +476,7 @@ class Meta:
]
widgets = {
"title": TextInputWidget(),
"siglum": TextInputWidget(),
# "siglum": TextInputWidget(),
"incipit": TextInputWidget(),
"folio": TextInputWidget(),
"s_sequence": TextInputWidget(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"CDN-NVanBCpc",
"CDN-SYpc",
"NL-EINpc",
"BR-PApc"
"BR-PApc",
}

siglum_to_country = {
Expand Down Expand Up @@ -99,7 +99,7 @@
"N-N.miss.imp.1519",
"D-A/imp:1498",
"D-P/imp1511",
"D-WÜ/imp1583"
"D-WÜ/imp1583",
}


Expand Down Expand Up @@ -159,7 +159,11 @@ def handle(self, *args, **options):
insts_city[siglum].add(city.strip())
insts_ids[siglum].add(source.id)

if options["lookup"] and (siglum not in bad_sigla or siglum not in private_collections or siglum not in insts_rism):
if options["lookup"] and (
siglum not in bad_sigla
or siglum not in private_collections
or siglum not in insts_rism
):
req = requests.get(
f"https://rism.online/sigla/{siglum}",
allow_redirects=True,
Expand Down Expand Up @@ -194,9 +198,7 @@ def handle(self, *args, **options):
print("siglum,city,country,name,alt_names")

print_inst = Institution.objects.create(
name="Print (Multiple Copies)",
siglum="XX-NN",
city=None
name="Print (Multiple Copies)", siglum="XX-NN", city=None
)

for sig, names in insts_name.items():
Expand All @@ -222,7 +224,9 @@ def handle(self, *args, **options):
# Setting siglum to None will make it XX-NN
inst_sig = None

print(f"{inst_sig},{main_city},{inst_country},{main_name},{alt_names_fmt}")
print(
f"{inst_sig},{main_city},{inst_country},{main_name},{alt_names_fmt}"
)

if options["dry_run"]:
continue
Expand All @@ -239,14 +243,20 @@ def handle(self, *args, **options):
elif inst_sig is not None:
iobj["siglum"] = inst_sig
else:
print(self.style.WARNING(f"Could not create {inst_id}. Setting siglum to XX-NN"))
print(
self.style.WARNING(
f"Could not create {inst_id}. Setting siglum to XX-NN"
)
)
iobj["siglum"] = "XX-NN"

try:
holding_institution = Institution.objects.create(**iobj)
except ValidationError:
print(
self.style.WARNING(f"Could not create {sig} {main_name}. Setting institution to None")
self.style.WARNING(
f"Could not create {sig} {main_name}. Setting institution to None"
)
)
holding_institution = None

Expand Down Expand Up @@ -274,6 +284,4 @@ def handle(self, *args, **options):
s.holding_institution = holding_institution
s.shelfmark = shelfmark.strip()
s.save()
print(self.style.SUCCESS(
f"Saved update to Source {s.id}"
))
print(self.style.SUCCESS(f"Saved update to Source {s.id}"))
Loading
Loading