Skip to content

Commit

Permalink
Merge pull request #1645 from dchiller/i1628-source-printed
Browse files Browse the repository at this point in the history
  • Loading branch information
dchiller authored Oct 11, 2024
2 parents cc14cf5 + 8eb3df8 commit 1dfe503
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 227 deletions.
89 changes: 30 additions & 59 deletions django/cantusdb_project/main_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def label_from_instance(self, obj):
widget = CheckboxSelectMultiple()


class StyledChoiceField(forms.ChoiceField):
"""
A custom ChoiceField that uses the custom SelectWidget defined in widgets.py
as its widget (for styling).
"""

widget = SelectWidget()


class ChantCreateForm(forms.ModelForm):
class Meta:
model = Chant
Expand Down Expand Up @@ -191,6 +200,7 @@ class Meta:
# "siglum",
"holding_institution",
"shelfmark",
"name",
"segment_m2m",
"provenance",
"provenance_notes",
Expand All @@ -212,11 +222,15 @@ class Meta:
"fragmentarium_id",
"dact_id",
"indexing_notes",
"production_method",
"source_completeness",
]
widgets = {
# "title": TextInputWidget(),
# "siglum": TextInputWidget(),
"shelfmark": TextInputWidget(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"name": TextInputWidget(),
"provenance_notes": TextInputWidget(),
"date": TextInputWidget(),
"cursus": SelectWidget(),
Expand Down Expand Up @@ -246,39 +260,24 @@ class Meta:
"other_editors": autocomplete.ModelSelect2Multiple(
url="all-users-autocomplete"
),
"production_method": SelectWidget(),
"source_completeness": SelectWidget(),
}
field_classes = {
"segment_m2m": CheckboxNameModelMultipleChoiceField,
}

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

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

TRUE_FALSE_CHOICES_SOURCE = (
(True, "Full source"),
(False, "Fragment or Fragmented"),
)

full_source = forms.ChoiceField(choices=TRUE_FALSE_CHOICES_SOURCE, required=False)
full_source.widget.attrs.update(
{"class": "form-control custom-select custom-select-sm"}
)
TRUE_FALSE_CHOICES_INVEN = ((True, "Complete"), (False, "Incomplete"))

complete_inventory = forms.ChoiceField(
complete_inventory = StyledChoiceField(
choices=TRUE_FALSE_CHOICES_INVEN, required=False
)
complete_inventory.widget.attrs.update(
{"class": "form-control custom-select custom-select-sm"}
)


class ChantEditForm(forms.ModelForm):
Expand Down Expand Up @@ -391,6 +390,7 @@ class Meta:
# "siglum",
"holding_institution",
"shelfmark",
"name",
"segment_m2m",
"provenance",
"provenance_notes",
Expand All @@ -413,12 +413,17 @@ class Meta:
"full_text_entered_by",
"proofreaders",
"other_editors",
"production_method",
"source_completeness",
]
widgets = {
"shelfmark": TextInputWidget(),
"segment_m2m": CheckboxSelectMultiple(),
"name": TextInputWidget(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"provenance_notes": TextInputWidget(),
"date": TextInputWidget(),
"cursus": SelectWidget(),
"summary": TextAreaWidget(),
"liturgical_occasions": TextAreaWidget(),
"description": TextAreaWidget(),
Expand Down Expand Up @@ -446,48 +451,24 @@ class Meta:
"other_editors": autocomplete.ModelSelect2Multiple(
url="all-users-autocomplete"
),
"production_method": SelectWidget(),
"source_completeness": SelectWidget(),
}
field_classes = {
"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"),
required=False,
)

CHOICES_FULL_SOURCE = (
(None, "None"),
(True, "Full source"),
(False, "Fragment or Fragmented"),
)
full_source = forms.ChoiceField(choices=CHOICES_FULL_SOURCE, required=False)
full_source.widget.attrs.update(
{"class": "form-control custom-select custom-select-sm"}
)

CHOICES_CURSUS = (
(None, "None"),
("Monastic", "Monastic"),
("Secular", "Secular"),
)
cursus = forms.ChoiceField(choices=CHOICES_CURSUS, required=False)
cursus.widget.attrs.update({"class": "form-control custom-select custom-select-sm"})

CHOICES_COMPLETE_INV = (
(True, "complete inventory"),
(False, "partial inventory"),
)
complete_inventory = forms.ChoiceField(choices=CHOICES_COMPLETE_INV, required=False)
complete_inventory.widget.attrs.update(
{"class": "form-control custom-select custom-select-sm"}
)
complete_inventory = StyledChoiceField(choices=CHOICES_COMPLETE_INV, required=False)


class SequenceEditForm(forms.ModelForm):
Expand Down Expand Up @@ -733,19 +714,9 @@ class Meta:
# 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(
queryset=Institution.objects.all().order_by("name"),
required=True,
queryset=Institution.objects.all().order_by("city", "name"),
required=False,
)

provenance = forms.ModelChoiceField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def handle(self, *args, **options):
)
)
institution = print_inst
elif siglum in created_institutions:
elif siglum in created_institutions and source.id not in bad_siglum:
print(
self.style.SUCCESS(
f"Re-using the pre-created institution for {siglum}"
Expand All @@ -185,7 +185,7 @@ def handle(self, *args, **options):
institution.alternate_names = "\n".join(list(deduped_names))

institution.save()
elif siglum not in created_institutions:
elif siglum not in created_institutions and source.id not in bad_siglum:
print(self.style.SUCCESS(f"Creating institution record for {siglum}"))

iobj = {
Expand Down Expand Up @@ -229,6 +229,8 @@ def handle(self, *args, **options):
created_institutions[siglum] = institution

else:
source.shelfmark = shelfmark.strip()
source.save()
print(
self.style.ERROR(
f"Could not determine the holding institution for {source}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
A temporary command to populate the source_completeness field in the Source model,
based on the full_source field. This command will be removed once the source_completeness
is initially populated.
"""

from django.core.management.base import BaseCommand
from main_app.models import Source


class Command(BaseCommand):
def handle(self, *args, **options):
sources = Source.objects.all()
for source in sources:
if source.full_source:
source.source_completeness = (
source.SourceCompletenessChoices.FULL_SOURCE
)
else:
source.source_completeness = source.SourceCompletenessChoices.FRAGMENT
source.save()
self.stdout.write(self.style.SUCCESS("Source completeness populated"))

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Generated by Django 4.2.14 on 2024-10-02 17:01

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.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.AddField(
model_name="source",
name="production_method",
field=models.IntegerField(
choices=[(1, "Manuscript"), (2, "Printed")],
default=1,
verbose_name="Manuscript/Printed",
),
),
migrations.AddField(
model_name="source",
name="source_completeness",
field=models.IntegerField(
choices=[
(1, "Full source"),
(2, "Fragment/Fragmented"),
(3, "Reconstruction"),
],
default=1,
verbose_name="Full Source/Fragment",
),
),
migrations.AlterField(
model_name="institution",
name="country",
field=models.CharField(default="[No Country]", max_length=64),
),
migrations.AlterField(
model_name="institution",
name="name",
field=models.CharField(default="[No Name]", max_length=255),
),
migrations.AlterField(
model_name="source",
name="shelfmark",
field=models.CharField(
default="[No Shelfmark]",
help_text="Primary Cantus Database identifier for the source (e.g. library shelfmark, DACT ID, etc.)",
max_length=255,
),
),
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",),
},
),
]
Loading

0 comments on commit 1dfe503

Please sign in to comment.