Skip to content

Commit

Permalink
Merge pull request DDMAL#1606 from lucasmarchd01/issue-1604
Browse files Browse the repository at this point in the history
Make `shelfmark` a required field on source create and edit forms
  • Loading branch information
lucasmarchd01 authored Aug 30, 2024
2 parents c3f78ae + d39d486 commit 28657a2
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 27 deletions.
11 changes: 9 additions & 2 deletions django/cantusdb_project/main_app/admin/institution.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ class InstitutionAdmin(BaseModelAdmin):
"get_city_region",
"country",
"is_private_collector",
"is_private_collection"
"is_private_collection",
)
search_fields = (
"name",
"siglum",
"city",
"region",
"alternate_names",
"migrated_identifier",
)
search_fields = ("name", "siglum", "city", "region", "alternate_names", "migrated_identifier")
readonly_fields = ("migrated_identifier",)
list_filter = ("is_private_collector", "is_private_collection", "city")
inlines = (InstitutionIdentifierInline, InstitutionSourceInline)
Expand Down
41 changes: 33 additions & 8 deletions django/cantusdb_project/main_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Chant,
Service,
Genre,
Institution,
Notation,
Feast,
Source,
Expand Down Expand Up @@ -215,10 +216,6 @@ class Meta:
widgets = {
# "title": TextInputWidget(),
# "siglum": TextInputWidget(),
"holding_institution": autocomplete.ModelSelect2(
url="holding-autocomplete"
),
"shelfmark": TextInputWidget(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"provenance_notes": TextInputWidget(),
"date": TextInputWidget(),
Expand Down Expand Up @@ -254,6 +251,17 @@ class Meta:
"segment_m2m": CheckboxNameModelMultipleChoiceField,
}

holding_institution = forms.ModelChoiceField(
queryset=Institution.objects.all(),
required=True,
widget=autocomplete.ModelSelect2(url="holding-autocomplete"),
)

shelfmark = forms.CharField(
required=True,
widget=TextInputWidget,
)

TRUE_FALSE_CHOICES_SOURCE = (
(True, "Full source"),
(False, "Fragment or Fragmented"),
Expand Down Expand Up @@ -407,10 +415,6 @@ class Meta:
"other_editors",
]
widgets = {
"holding_institution": autocomplete.ModelSelect2(
url="holding-autocomplete"
),
"shelfmark": TextInputWidget(),
"segment_m2m": CheckboxSelectMultiple(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"provenance_notes": TextInputWidget(),
Expand Down Expand Up @@ -447,6 +451,17 @@ class Meta:
"segment_m2m": CheckboxNameModelMultipleChoiceField,
}

shelfmark = forms.CharField(
required=True,
widget=TextInputWidget,
)

holding_institution = forms.ModelChoiceField(
queryset=Institution.objects.all(),
required=True,
widget=autocomplete.ModelSelect2(url="holding-autocomplete"),
)

CHOICES_FULL_SOURCE = (
(None, "None"),
(True, "Full source"),
Expand Down Expand Up @@ -718,6 +733,16 @@ class Meta:
help_text="RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).",
)

shelfmark = forms.CharField(
required=True,
widget=TextInputWidget,
)

holding_institution = forms.ModelChoiceField(
queryset=Institution.objects.all().order_by("name"),
required=True,
)

provenance = forms.ModelChoiceField(
queryset=Provenance.objects.all().order_by("name"),
required=False,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.14 on 2024-08-30 13:58

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("main_app", "0030_institution_is_private_collection"),
]

operations = [
migrations.AlterField(
model_name="source",
name="holding_institution",
field=models.ForeignKey(
default=19,
on_delete=django.db.models.deletion.PROTECT,
to="main_app.institution",
),
preserve_default=False,
),
migrations.AlterField(
model_name="source",
name="shelfmark",
field=models.CharField(
default="XX-NN",
max_length=255,
),
),
]
2 changes: 1 addition & 1 deletion django/cantusdb_project/main_app/models/institution.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Meta:
max_length=64,
blank=True,
null=True,
help_text="Former Cantus identifier. Should not be used for new records."
help_text="Former Cantus identifier. Should not be used for new records.",
)

def __str__(self) -> str:
Expand Down
8 changes: 4 additions & 4 deletions django/cantusdb_project/main_app/models/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class Source(BaseModel):
holding_institution = models.ForeignKey(
"Institution",
on_delete=models.PROTECT,
null=True,
blank=True,
null=False,
blank=False,
)
shelfmark = models.CharField(
max_length=255,
blank=True,
null=True,
blank=False,
null=False,
)
provenance = models.ForeignKey(
"Provenance",
Expand Down
12 changes: 6 additions & 6 deletions django/cantusdb_project/main_app/templates/source_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ <h3>Create Source</h3>
<form method="post" style="line-height: normal">{% csrf_token %}
<div class="form-row">
<div class="form-group m-1 col-lg-3">
<label for="{{ form.holding_institution.id_for_label }}">
<small>Holding Institution:</small>
<label for="{{ form.holding_institution.id_for_label }}" class="form-control-sm">
Holding Institution:<span class="text-danger" title="This field is required">*</span>
</label>
<br>{{ form.holding_institution }}
{{ form.holding_institution }}
<p class=text-muted>
<small>{{ form.holding_institution.help_text }}</small>
</p>
</div>
</div>
<div class="form-row">
<div class="form-group m-1 col-lg-3">
<label for="{{ form.shelfmark.id_for_label }}">
<small>Shelfmark:</small>
<label for="{{ form.shelfmark.id_for_label }}" class="form-control-sm">
Shelfmark:<span class="text-danger" title="This field is required">*</span>
</label>
<br>{{ form.shelfmark }}
{{ form.shelfmark }}
<p class=text-muted>
<small>{{ form.shelfmark.help_text }}</small>
</p>
Expand Down
12 changes: 6 additions & 6 deletions django/cantusdb_project/main_app/templates/source_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ <h3>
<form method="post" style="line-height: normal">{% csrf_token %}
<div class="form-row">
<div class="form-group m-1 col-lg-3">
<label for="{{ form.holding_institution.id_for_label }}">
<small>Holding Institution:</small>
<label for="{{ form.holding_institution.id_for_label }}" class="form-control-sm">
Holding Institution:<span class="text-danger" title="This field is required">*</span>
</label>
<br>{{ form.holding_institution }}
{{ form.holding_institution }}
<p class=text-muted>
<small>{{ form.holding_institution.help_text }}</small>
</p>
</div>
</div>
<div class="form-row">
<div class="form-group m-1 col-lg-3">
<label for="{{ form.shelfmark.id_for_label }}">
<small>Shelfmark:</small>
<label for="{{ form.shelfmark.id_for_label }}" class="form-control-sm">
Shelfmark:<span class="text-danger" title="This field is required">*</span>
</label>
<br>{{ form.shelfmark }}
{{ form.shelfmark }}
<p class=text-muted>
<small>{{ form.shelfmark.help_text }}</small>
</p>
Expand Down
4 changes: 4 additions & 0 deletions django/cantusdb_project/main_app/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4828,10 +4828,12 @@ def test_url_and_templates(self):
self.assertTemplateUsed(response, "source_create.html")

def test_create_source(self):
hinst = make_fake_institution(siglum="FA-Ke")
response = self.client.post(
reverse("source-create"),
{
"shelfmark": "test-shelfmark", # shelfmark is a required field
"holding_institution": hinst.id, # holding institution is a required field
},
)

Expand Down Expand Up @@ -4878,11 +4880,13 @@ def test_url_and_templates(self):

def test_edit_source(self):
source = make_fake_source()
hinst = make_fake_institution(siglum="FA-Ke")

response = self.client.post(
reverse("source-edit", args=[source.id]),
{
"shelfmark": "test-shelfmark", # shelfmark is a required field,
"holding_institution": hinst.id, # holding institution is a required field
},
)

Expand Down

0 comments on commit 28657a2

Please sign in to comment.