From ec8a85146144b2d68e969ce1b805b5b74b8998a8 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 19 Aug 2024 16:46:40 +0000 Subject: [PATCH 1/7] fix(source): fix TypeError on source create page - make shelfmark a required field on source create and edit pages --- django/cantusdb_project/main_app/forms.py | 12 ++++++++++-- .../main_app/templates/source_create.html | 2 +- .../main_app/templates/source_edit.html | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/django/cantusdb_project/main_app/forms.py b/django/cantusdb_project/main_app/forms.py index e1f6e11f8..1652e430e 100644 --- a/django/cantusdb_project/main_app/forms.py +++ b/django/cantusdb_project/main_app/forms.py @@ -218,7 +218,6 @@ class Meta: "holding_institution": autocomplete.ModelSelect2( url="holding-autocomplete" ), - "shelfmark": TextInputWidget(), "provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"), "provenance_notes": TextInputWidget(), "date": TextInputWidget(), @@ -254,6 +253,11 @@ class Meta: "segment_m2m": CheckboxNameModelMultipleChoiceField, } + shelfmark = forms.CharField( + required=True, + widget=TextInputWidget, + ) + TRUE_FALSE_CHOICES_SOURCE = ( (True, "Full source"), (False, "Fragment or Fragmented"), @@ -410,7 +414,6 @@ class Meta: "holding_institution": autocomplete.ModelSelect2( url="holding-autocomplete" ), - "shelfmark": TextInputWidget(), "segment_m2m": CheckboxSelectMultiple(), "provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"), "provenance_notes": TextInputWidget(), @@ -447,6 +450,11 @@ class Meta: "segment_m2m": CheckboxNameModelMultipleChoiceField, } + shelfmark = forms.CharField( + required=True, + widget=TextInputWidget, + ) + CHOICES_FULL_SOURCE = ( (None, "None"), (True, "Full source"), diff --git a/django/cantusdb_project/main_app/templates/source_create.html b/django/cantusdb_project/main_app/templates/source_create.html index 541ef7eab..f3a98c67e 100644 --- a/django/cantusdb_project/main_app/templates/source_create.html +++ b/django/cantusdb_project/main_app/templates/source_create.html @@ -57,7 +57,7 @@

Create Source


{{ form.shelfmark }}

diff --git a/django/cantusdb_project/main_app/templates/source_edit.html b/django/cantusdb_project/main_app/templates/source_edit.html index 869a5164b..a5390f112 100644 --- a/django/cantusdb_project/main_app/templates/source_edit.html +++ b/django/cantusdb_project/main_app/templates/source_edit.html @@ -59,7 +59,7 @@


{{ form.shelfmark }}

From c49eb5143a78596459e2182718bfa58522af69ff Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 19 Aug 2024 16:50:26 +0000 Subject: [PATCH 2/7] fix(source): fix TypeError on source create page - make shelfmark a required field on source create and edit pages - make shelfmark a required field on admin source add form --- django/cantusdb_project/main_app/forms.py | 17 +++++++++++++++-- .../main_app/templates/source_create.html | 2 +- .../main_app/templates/source_edit.html | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/django/cantusdb_project/main_app/forms.py b/django/cantusdb_project/main_app/forms.py index e1f6e11f8..c1cf89745 100644 --- a/django/cantusdb_project/main_app/forms.py +++ b/django/cantusdb_project/main_app/forms.py @@ -218,7 +218,6 @@ class Meta: "holding_institution": autocomplete.ModelSelect2( url="holding-autocomplete" ), - "shelfmark": TextInputWidget(), "provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"), "provenance_notes": TextInputWidget(), "date": TextInputWidget(), @@ -254,6 +253,11 @@ class Meta: "segment_m2m": CheckboxNameModelMultipleChoiceField, } + shelfmark = forms.CharField( + required=True, + widget=TextInputWidget, + ) + TRUE_FALSE_CHOICES_SOURCE = ( (True, "Full source"), (False, "Fragment or Fragmented"), @@ -410,7 +414,6 @@ class Meta: "holding_institution": autocomplete.ModelSelect2( url="holding-autocomplete" ), - "shelfmark": TextInputWidget(), "segment_m2m": CheckboxSelectMultiple(), "provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"), "provenance_notes": TextInputWidget(), @@ -447,6 +450,11 @@ class Meta: "segment_m2m": CheckboxNameModelMultipleChoiceField, } + shelfmark = forms.CharField( + required=True, + widget=TextInputWidget, + ) + CHOICES_FULL_SOURCE = ( (None, "None"), (True, "Full source"), @@ -718,6 +726,11 @@ class Meta: help_text="RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).", ) + shelfmark = forms.CharField( + required=True, + widget=TextInputWidget, + ) + provenance = forms.ModelChoiceField( queryset=Provenance.objects.all().order_by("name"), required=False, diff --git a/django/cantusdb_project/main_app/templates/source_create.html b/django/cantusdb_project/main_app/templates/source_create.html index 541ef7eab..f3a98c67e 100644 --- a/django/cantusdb_project/main_app/templates/source_create.html +++ b/django/cantusdb_project/main_app/templates/source_create.html @@ -57,7 +57,7 @@

Create Source


{{ form.shelfmark }}

diff --git a/django/cantusdb_project/main_app/templates/source_edit.html b/django/cantusdb_project/main_app/templates/source_edit.html index 869a5164b..a5390f112 100644 --- a/django/cantusdb_project/main_app/templates/source_edit.html +++ b/django/cantusdb_project/main_app/templates/source_edit.html @@ -59,7 +59,7 @@


{{ form.shelfmark }}

From 5e72103a6a20d6cb65ff2b29e834540d8a773adf Mon Sep 17 00:00:00 2001 From: lucasmarchd01 Date: Fri, 23 Aug 2024 18:41:13 +0000 Subject: [PATCH 3/7] fix(source): make holding institution and shelfmark fields required - in source model - on the source create and edit forms --- django/cantusdb_project/main_app/forms.py | 24 ++++++++++++++----- .../main_app/models/source.py | 8 +++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/django/cantusdb_project/main_app/forms.py b/django/cantusdb_project/main_app/forms.py index c1cf89745..81dce3c75 100644 --- a/django/cantusdb_project/main_app/forms.py +++ b/django/cantusdb_project/main_app/forms.py @@ -4,6 +4,7 @@ Chant, Service, Genre, + Institution, Notation, Feast, Source, @@ -215,9 +216,6 @@ class Meta: widgets = { # "title": TextInputWidget(), # "siglum": TextInputWidget(), - "holding_institution": autocomplete.ModelSelect2( - url="holding-autocomplete" - ), "provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"), "provenance_notes": TextInputWidget(), "date": TextInputWidget(), @@ -253,6 +251,12 @@ 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, @@ -411,9 +415,6 @@ class Meta: "other_editors", ] widgets = { - "holding_institution": autocomplete.ModelSelect2( - url="holding-autocomplete" - ), "segment_m2m": CheckboxSelectMultiple(), "provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"), "provenance_notes": TextInputWidget(), @@ -455,6 +456,12 @@ class Meta: 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"), @@ -731,6 +738,11 @@ class Meta: 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, diff --git a/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py index 988942128..919fbac20 100644 --- a/django/cantusdb_project/main_app/models/source.py +++ b/django/cantusdb_project/main_app/models/source.py @@ -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", From c7f760c3ccc879d702f531471c30dde337106560 Mon Sep 17 00:00:00 2001 From: lucasmarchd01 Date: Fri, 23 Aug 2024 18:42:01 +0000 Subject: [PATCH 4/7] fix(source): change templates to include required fields - holding institution and shelfmark fields are now required - fixes incorrect use of tag on these fields --- .../main_app/templates/source_create.html | 12 ++++++------ .../main_app/templates/source_edit.html | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/django/cantusdb_project/main_app/templates/source_create.html b/django/cantusdb_project/main_app/templates/source_create.html index f3a98c67e..62a8d50a3 100644 --- a/django/cantusdb_project/main_app/templates/source_create.html +++ b/django/cantusdb_project/main_app/templates/source_create.html @@ -45,10 +45,10 @@

Create Source

{% csrf_token %}
-
- + -
{{ form.shelfmark }} + {{ form.shelfmark }}

{{ form.shelfmark.help_text }}

diff --git a/django/cantusdb_project/main_app/templates/source_edit.html b/django/cantusdb_project/main_app/templates/source_edit.html index a5390f112..89d876b07 100644 --- a/django/cantusdb_project/main_app/templates/source_edit.html +++ b/django/cantusdb_project/main_app/templates/source_edit.html @@ -47,10 +47,10 @@

{% csrf_token %}
-
-