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

Make shelfmark a required field on source create and edit forms #1606

Merged
merged 9 commits into from
Aug 30, 2024
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
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 @@ -4679,10 +4679,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 @@ -4729,11 +4731,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
Loading