Skip to content

Commit

Permalink
Fixed: Remove the RISM Sigla table
Browse files Browse the repository at this point in the history
This removes the RISM Sigla table and all the places where it is referenced in the code.

I have saved a local backup of the data in CSV before exporting.

Running the migration will delete the table and all the data in the database.

Fixes #1508

# Conflicts:
#	django/cantusdb_project/main_app/models/source.py
  • Loading branch information
ahankinson committed Jun 13, 2024
1 parent 2d213fd commit bd22850
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 172 deletions.
1 change: 0 additions & 1 deletion django/cantusdb_project/main_app/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from main_app.admin.notation import NotationAdmin
from main_app.admin.office import OfficeAdmin
from main_app.admin.provenance import ProvenanceAdmin
from main_app.admin.rism_siglum import RismSiglumAdmin
from main_app.admin.segment import SegmentAdmin
from main_app.admin.sequence import SequenceAdmin
from main_app.admin.source import SourceAdmin
Expand Down
11 changes: 0 additions & 11 deletions django/cantusdb_project/main_app/admin/rism_siglum.py

This file was deleted.

18 changes: 0 additions & 18 deletions django/cantusdb_project/main_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Notation,
Feast,
Source,
RismSiglum,
Segment,
Provenance,
Century,
Expand Down Expand Up @@ -176,7 +175,6 @@ class Meta:
model = Source
fields = [
"title",
"rism_siglum",
"siglum",
"provenance",
"provenance_notes",
Expand Down Expand Up @@ -213,7 +211,6 @@ class Meta:
"fragmentarium_id": TextInputWidget(),
"dact_id": TextInputWidget(),
"indexing_notes": TextAreaWidget(),
"rism_siglum": autocomplete.ModelSelect2(url="rismsiglum-autocomplete"),
"current_editors": autocomplete.ModelSelect2Multiple(
url="current-editors-autocomplete"
),
Expand Down Expand Up @@ -365,7 +362,6 @@ class Meta:
model = Source
fields = [
"title",
"rism_siglum",
"siglum",
"provenance",
"provenance_notes",
Expand All @@ -391,7 +387,6 @@ class Meta:
]
widgets = {
"title": TextInputWidget(),
"rism_siglum": autocomplete.ModelSelect2(url="rismsiglum-autocomplete"),
"siglum": TextInputWidget(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"provenance_notes": TextInputWidget(),
Expand Down Expand Up @@ -634,14 +629,6 @@ class Meta:
name = forms.CharField(required=True, widget=TextInputWidget)


class AdminRismSiglumForm(forms.ModelForm):
class Meta:
model = RismSiglum
fields = "__all__"

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


class AdminSegmentForm(forms.ModelForm):
class Meta:
model = Segment
Expand Down Expand Up @@ -704,11 +691,6 @@ class Meta:
help_text="RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).",
)

rism_siglum = forms.ModelChoiceField(
queryset=RismSiglum.objects.all().order_by("name"),
required=False,
)

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,20 @@
# Generated by Django 4.2.11 on 2024-06-13 11:43

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("main_app", "0018_institution_former_sigla"),
]

operations = [
migrations.RemoveField(
model_name="source",
name="rism_siglum",
),
migrations.DeleteModel(
name="RismSiglum",
),
]
1 change: 0 additions & 1 deletion django/cantusdb_project/main_app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from main_app.models.provenance import Provenance
from main_app.models.segment import Segment
from main_app.models.sequence import Sequence
from main_app.models.rism_siglum import RismSiglum
from main_app.models.source import Source
from main_app.models.institution import Institution
from main_app.models.institution_identifier import InstitutionIdentifier
22 changes: 0 additions & 22 deletions django/cantusdb_project/main_app/models/rism_siglum.py

This file was deleted.

7 changes: 0 additions & 7 deletions django/cantusdb_project/main_app/models/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ class Source(BaseModel):
blank=False,
help_text="RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).",
)
# the RISM siglum uniquely identifies a library or holding institution
rism_siglum = models.ForeignKey(
"RismSiglum",
on_delete=models.PROTECT,
null=True,
blank=True,
)
holding_institution = models.ForeignKey(
"Institution",
on_delete=models.PROTECT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h3>Content Overview</h3>
</td>
{% elif object.name %}
<td class="text-wrap" style="text-align:center">
{% if object|classname == "Notation" or object|classname == "Segment" or object|classname == "RismSiglum" %}
{% if object|classname == "Notation" or object|classname == "Segment" %}
<b>{{ object.name|truncatechars:30 }}
{% else %}
<a href="{{ object.get_absolute_url }}"><b>{{ object.name|truncatechars:30 }}</b></a>
Expand Down
11 changes: 0 additions & 11 deletions django/cantusdb_project/main_app/templates/source_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ <h3>Create Source</h3>
</label>
{{ form.title }}
</div>

<div class="form-group m-1 col-lg-3">
<label for="{{ form.rism_siglum.id_for_label }}">
<small>RISM:</small>
</label>
<br>{{ form.rism_siglum }}
<small>
<a href="https://rism.info/community/sigla.html" target="_blank">Browse RISM sigla</a>
(opens in new tab)
</small>
</div>
</div>

<div class="form-row">
Expand Down
13 changes: 0 additions & 13 deletions django/cantusdb_project/main_app/templates/source_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ <h3><em>Edit Source</em> {{ source.title }}</h3>
</div>
</div>

<div class="form-row mb-3">
<div class="form-group m-1 col-3">
<label for="{{ form.rism_siglum.id_for_label }}">
RISM:
</label>
{{ form.rism_siglum }}
<small>
<a href="https://rism.info/community/sigla.html" target="_blank">Browse RISM sigla</a>
(opens in new tab)
</small>
</div>
</div>

<div class="form-row mb-3">
<div class="form-group m-1 col-lg-9">
<label for="{{ form.siglum.id_for_label }}">
Expand Down
14 changes: 0 additions & 14 deletions django/cantusdb_project/main_app/tests/make_fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from main_app.models import Notation
from main_app.models import Office
from main_app.models import Provenance
from main_app.models import RismSiglum
from main_app.models import Segment
from main_app.models import Sequence
from main_app.models import Source
Expand Down Expand Up @@ -293,15 +292,6 @@ def make_fake_provenance() -> Provenance:
return provenance


def make_fake_rism_siglum() -> RismSiglum:
"""Generates a fake RismSiglum object."""
rism_siglum = RismSiglum.objects.create(
name=faker.sentence(nb_words=3),
description=faker.sentence(),
)
return rism_siglum


def make_fake_segment(name: str = None, id: int = None) -> Segment:
"""Generates a fake Segment object."""
if name is None:
Expand Down Expand Up @@ -349,7 +339,6 @@ def make_fake_source(
segment_name: Optional[str] = None,
segment: Optional[Segment] = None,
siglum: Optional[str] = None,
rism_siglum: Optional[RismSiglum] = None,
description: Optional[str] = None,
summary: Optional[str] = None,
provenance: Optional[Provenance] = None,
Expand All @@ -371,8 +360,6 @@ def make_fake_source(
segment = make_fake_segment(name=segment_name)
if siglum is None:
siglum = make_random_string(6)
if rism_siglum is None:
rism_siglum = make_fake_rism_siglum()
if description is None:
description = faker.sentence()
if summary is None:
Expand All @@ -394,7 +381,6 @@ def make_fake_source(
title=title,
segment=segment,
siglum=siglum,
rism_siglum=rism_siglum,
description=description,
summary=summary,
provenance=provenance,
Expand Down
46 changes: 2 additions & 44 deletions django/cantusdb_project/main_app/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
make_fake_notation,
make_fake_office,
make_fake_provenance,
make_fake_rism_siglum,
make_fake_segment,
make_fake_sequence,
make_fake_source,
Expand Down Expand Up @@ -1292,7 +1291,6 @@ def test_order_by_office(self):
self.assertEqual(last_result_incipit, chant_1.incipit)

def test_order_by_office_global_search(self):

# currently, office sort works by ID rather than by name
office_1 = make_fake_office()
office_2 = make_fake_office()
Expand Down Expand Up @@ -4452,7 +4450,7 @@ def test_filter_by_full_source(self):
self.assertIn(unknown, sources)

def test_search_by_title(self):
"""The "general search" field searches in `title`, `siglum`, `rism_siglum`, `description`, and `summary`"""
"""The "general search" field searches in `title`, `siglum`, `description`, and `summary`"""
source = make_fake_source(
title=faker.sentence(),
published=True,
Expand Down Expand Up @@ -4487,44 +4485,6 @@ def test_search_by_siglum(self):
response = self.client.get(reverse("source-list"), {"general": search_term})
self.assertIn(source, response.context["sources"])

def test_search_by_rism_siglum_name(self):
rism_siglum = make_fake_rism_siglum()
source = make_fake_source(
rism_siglum=rism_siglum,
published=True,
title="title",
)
search_term = get_random_search_term(source.rism_siglum.name)
response = self.client.get(reverse("source-list"), {"general": search_term})
self.assertIn(source, response.context["sources"])

# Test that postgres searches unaccented version of RISM siglum name
unaccented_name = rism_siglum.name
accented_name = add_accents_to_string(unaccented_name)
rism_siglum.name = accented_name
rism_siglum.save()
response = self.client.get(reverse("source-list"), {"general": search_term})
self.assertIn(source, response.context["sources"])

def test_search_by_rism_siglum_description(self):
rism_siglum = make_fake_rism_siglum()
source = make_fake_source(
rism_siglum=rism_siglum,
published=True,
title="title",
)
search_term = get_random_search_term(source.rism_siglum.description)
response = self.client.get(reverse("source-list"), {"general": search_term})
self.assertIn(source, response.context["sources"])

# Test that postgres searches unaccented version of RISM siglum description
unaccented_description = rism_siglum.description
accented_description = add_accents_to_string(unaccented_description)
rism_siglum.description = accented_description
rism_siglum.save()
response = self.client.get(reverse("source-list"), {"general": search_term})
self.assertIn(source, response.context["sources"])

def test_search_by_description(self):
source = make_fake_source(
description=faker.sentence(),
Expand Down Expand Up @@ -5003,9 +4963,7 @@ def test_dd_column(self):
response = self.client.get(reverse("source-inventory", args=[source.id]))
html: str = str(response.content)
self.assertIn(diff_id, html)
expected_html_substring: str = (
f'<a href="https://differentiaedatabase.ca/differentia/{diff_id}" target="_blank">'
)
expected_html_substring: str = f'<a href="https://differentiaedatabase.ca/differentia/{diff_id}" target="_blank">'
self.assertIn(expected_html_substring, html)

def test_redirect_with_source_parameter(self):
Expand Down
6 changes: 0 additions & 6 deletions django/cantusdb_project/main_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
CurrentEditorsAutocomplete,
AllUsersAutocomplete,
CenturyAutocomplete,
RismSiglumAutocomplete,
FeastAutocomplete,
OfficeAutocomplete,
GenreAutocomplete,
Expand Down Expand Up @@ -475,11 +474,6 @@
CenturyAutocomplete.as_view(),
name="century-autocomplete",
),
path(
"rismsiglum-autocomplete/",
RismSiglumAutocomplete.as_view(),
name="rismsiglum-autocomplete",
),
path(
"feast-autocomplete/",
FeastAutocomplete.as_view(),
Expand Down
16 changes: 5 additions & 11 deletions django/cantusdb_project/main_app/views/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ def get_context_data(self, **kwargs):

def get_queryset(self):
# use select_related() for foreign keys to reduce DB queries
queryset = Source.objects.select_related(
"rism_siglum", "segment", "provenance"
).order_by("siglum")
queryset = Source.objects.select_related("segment", "provenance").order_by(
"siglum"
)

display_unpublished = self.request.user.is_authenticated
if display_unpublished:
Expand Down Expand Up @@ -250,7 +250,6 @@ def get_queryset(self):
# We need a Q Object for each field we're gonna look into
title_q = Q()
siglum_q = Q()
rism_siglum_q = Q()
description_q = Q()
# it seems that old cantus don't look into title and provenance for the general search terms
# cantus.uwaterloo.ca/source/123901 this source cannot be found by searching its provenance 'Kremsmünster' in the general search field
Expand All @@ -264,21 +263,16 @@ def get_queryset(self):
for term in general_search_terms:
title_q |= Q(title__unaccent__icontains=term)
siglum_q |= Q(siglum__unaccent__icontains=term)
rism_siglum_q |= Q(rism_siglum__name__unaccent__icontains=term) | Q(
rism_siglum__description__unaccent__icontains=term
)
description_q |= Q(description__unaccent__icontains=term)
summary_q |= Q(summary__unaccent__icontains=term)
# provenance_q |= Q(provenance__name__icontains=term)
# All the Q objects are put together with OR.
# The end result is that at least one term has to match in at least one
# field
# general_search_q = (
# title_q | siglum_q | rism_siglum_q | description_q | provenance_q
# title_q | siglum_q | description_q | provenance_q
# )
general_search_q = (
title_q | siglum_q | rism_siglum_q | description_q | summary_q
)
general_search_q = title_q | siglum_q | description_q | summary_q
q_obj_filter &= general_search_q

# For the indexing notes search we follow the same procedure as above but with
Expand Down
Loading

0 comments on commit bd22850

Please sign in to comment.