Skip to content

Commit

Permalink
Merge pull request #1548 from dchiller/i1541-return-segment-to-source…
Browse files Browse the repository at this point in the history
…-level

Add `Project` model for chants & return segment to a source-level object
  • Loading branch information
dchiller authored Jul 10, 2024
2 parents 653bf52 + 97c7bd7 commit f17e934
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 188 deletions.
1 change: 1 addition & 0 deletions django/cantusdb_project/main_app/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from main_app.admin.source import SourceAdmin
from main_app.admin.institution import InstitutionAdmin
from main_app.admin.institution_identifier import InstitutionIdentifierAdmin
from main_app.admin.project import ProjectAdmin
9 changes: 9 additions & 0 deletions django/cantusdb_project/main_app/admin/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin

from main_app.admin.base_admin import BaseModelAdmin
from main_app.models import Project


@admin.register(Project)
class ProjectAdmin(BaseModelAdmin):
search_fields = ("name",)
70 changes: 32 additions & 38 deletions django/cantusdb_project/main_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Feast,
Source,
Segment,
Project,
Provenance,
Century,
Sequence,
Expand Down Expand Up @@ -82,14 +83,13 @@ class Meta:
"content_structure",
"indexing_notes",
"addendum",
# See issue #1521: Temporarily commenting out segment-related functions on Chant
# "segment",
# "liturgical_function",
# "polyphony",
# "cm_melody_id",
# "incipit_of_refrain",
# "later_addition",
# "rubrics",
"project",
"liturgical_function",
"polyphony",
"cm_melody_id",
"incipit_of_refrain",
"later_addition",
"rubrics",
]
# the widgets dictionary is ignored for a model field with a non-empty
# choices attribute. In this case, you must override the form field to
Expand Down Expand Up @@ -148,14 +148,12 @@ class Meta:
"Mass Alleluias. Punctuation is omitted.",
)

# See issue #1521: Temporarily commenting out segment-related functions on Chant
# segment = SelectWidgetNameModelChoiceField(
# queryset=Segment.objects.all().order_by("id"),
# required=True,
# initial=Segment.objects.get(id=4063), # Default to the "Cantus" segment
# help_text="Select the Database segment that the chant belongs to. "
# "In most cases, this will be the CANTUS segment.",
# )
project = SelectWidgetNameModelChoiceField(
queryset=Project.objects.all().order_by("id"),
initial=None,
required=False,
help_text="Select the project (if any) that the chant belongs to.",
)

# automatically computed fields
# source and incipit are mandatory fields in model,
Expand Down Expand Up @@ -280,14 +278,13 @@ class Meta:
"manuscript_full_text_proofread",
"volpiano_proofread",
"proofread_by",
# See issue #1521: Temporarily commenting out segment-related functions on Chant
# "segment",
# "liturgical_function",
# "polyphony",
# "cm_melody_id",
# "incipit_of_refrain",
# "later_addition",
# "rubrics",
"project",
"liturgical_function",
"polyphony",
"cm_melody_id",
"incipit_of_refrain",
"later_addition",
"rubrics",
]
widgets = {
# manuscript_full_text_std_spelling: defined below (required)
Expand Down Expand Up @@ -317,13 +314,12 @@ class Meta:
"proofread_by": autocomplete.ModelSelect2Multiple(
url="proofread-by-autocomplete"
),
# See issue #1521: Temporarily commenting out segment-related functions on Chant
# "polyphony": SelectWidget(),
# "liturgical_function": SelectWidget(),
# "cm_melody_id": TextInputWidget(),
# "incipit_of_refrain": TextInputWidget(),
# "later_addition": TextInputWidget(),
# "rubrics": TextInputWidget(),
"polyphony": SelectWidget(),
"liturgical_function": SelectWidget(),
"cm_melody_id": TextInputWidget(),
"incipit_of_refrain": TextInputWidget(),
"later_addition": TextInputWidget(),
"rubrics": TextInputWidget(),
}

manuscript_full_text_std_spelling = forms.CharField(
Expand All @@ -348,13 +344,11 @@ class Meta:
help_text="Each folio starts with '1'.",
)

# See issue #1521: Temporarily commenting out segment-related functions on Chant
# segment = SelectWidgetNameModelChoiceField(
# queryset=Segment.objects.all().order_by("id"),
# required=True,
# help_text="Select the Database segment that the chant belongs to. "
# "In most cases, this will be the CANTUS segment.",
# )
project = SelectWidgetNameModelChoiceField(
queryset=Project.objects.all().order_by("id"),
help_text="Select the project (if any) that the chant belongs to.",
required = False,
)


class SourceEditForm(forms.ModelForm):
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
This command is meant to be used one time toward solving issue
1542, assigning chants and sequences, where necessary, to their appropriate
"project".
This command assigns sequences to the Bower project. Chants
(in non-Bower sources) currently have
project.
Note: This command can only be run *after* the Bower project has been created
in the database through the Admin interface.
Note: This command is designed to be run once in order to complete the necessary
data migrations with the introduction of the Project model. It is not intended
for multiple runs.
"""

from django.core.management.base import BaseCommand
from main_app.models import Project, Sequence


class Command(BaseCommand):
help = "Assigns all sequences to the Bower project."

def handle(self, *args, **options):
sequences = Sequence.objects.all()
bower_project = Project.objects.get(name="Clavis Sequentiarum")
if not bower_project:
self.stdout.write(
self.style.ERROR(
"The Bower project does not exist. Please create it in the Admin interface."
)
)
return
sequences.update(project=bower_project)
self.stdout.write(
self.style.SUCCESS(
f"All sequences have been assigned to the {bower_project} project."
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Generated by Django 4.2.11 on 2024-06-18 13:04

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


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("main_app", "0019_remove_source_rism_siglum_delete_rismsiglum"),
]

operations = [
migrations.RemoveField(
model_name="chant",
name="segment",
),
migrations.RemoveField(
model_name="sequence",
name="segment",
),
migrations.CreateModel(
name="Project",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"date_created",
models.DateTimeField(
auto_now_add=True, help_text="The date this entry was created"
),
),
(
"date_updated",
models.DateTimeField(
auto_now=True, help_text="The date this entry was updated"
),
),
("name", models.CharField(max_length=63)),
(
"created_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_created_by_user",
to=settings.AUTH_USER_MODEL,
),
),
(
"last_updated_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_last_updated_by_user",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"abstract": False,
},
),
migrations.AddField(
model_name="chant",
name="project",
field=models.ForeignKey(
blank=True,
help_text="The project this chant belongs to. If left blank,this chant is considered part of the Cantus (default) project.",
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="main_app.project",
),
),
migrations.AddField(
model_name="sequence",
name="project",
field=models.ForeignKey(
blank=True,
help_text="The project this chant belongs to. If left blank,this chant is considered part of the Cantus (default) project.",
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="main_app.project",
),
),
]
1 change: 1 addition & 0 deletions django/cantusdb_project/main_app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
from main_app.models.source import Source
from main_app.models.institution import Institution
from main_app.models.institution_identifier import InstitutionIdentifier
from main_app.models.project import Project
9 changes: 6 additions & 3 deletions django/cantusdb_project/main_app/models/base_chant.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,15 @@ class Meta:
# this field, populated by the populate_is_last_chant_in_feast script, exists in order to optimize .get_suggested_feasts() on the chant-create page
is_last_chant_in_feast = models.BooleanField(blank=True, null=True)

segment = models.ForeignKey(
"Segment",
project = models.ForeignKey(
"Project",
on_delete=models.PROTECT,
null=True,
blank=True,
help_text="The segment of the manuscript that contains this chant",
help_text=(
"The project this chant belongs to. If left blank,"
"this chant is considered part of the Cantus (default) project."
),
)
# fragmentarium_id = models.CharField(blank=True, null=True, max_length=64)
# # Digital Analysis of Chant Transmission
Expand Down
16 changes: 16 additions & 0 deletions django/cantusdb_project/main_app/models/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from main_app.models import BaseModel
from django.db import models


class Project(BaseModel):
"""
Chants can be tagged with the Project if their inventories are collected
as part of a particular project or initiative. Tagging a chant with a
project allows for the collection of project-specific chant data during
the inventory process and enables filtering by project during search.
"""

name = models.CharField(max_length=63)

def __str__(self):
return f"{self.name} ({self.id})"
Loading

0 comments on commit f17e934

Please sign in to comment.