From 7cbb2fa309a50b88458da879b432f09223b7bb37 Mon Sep 17 00:00:00 2001 From: KK Date: Mon, 2 Sep 2024 11:05:20 +0200 Subject: [PATCH 1/2] refactor(models,api): remove remaining MultiSelectFields Remove leftover Expression edition_type field, Character fictionality field from models. Point to new ArrayFields and change field type to ListField in custom API endpoints. --- apis_ontology/api/serializers.py | 23 ++++++++++----- apis_ontology/api/views.py | 6 ++-- ..._remove_character_fictionality_and_more.py | 28 +++++++++++++++++++ apis_ontology/models.py | 21 -------------- 4 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 apis_ontology/migrations/0077_remove_character_fictionality_and_more.py diff --git a/apis_ontology/api/serializers.py b/apis_ontology/api/serializers.py index cd03c16..9386bff 100644 --- a/apis_ontology/api/serializers.py +++ b/apis_ontology/api/serializers.py @@ -66,7 +66,9 @@ class ExpressionDataSerializer(serializers.ModelSerializer): place_of_publication = PlaceDataSerializer( required=False, allow_null=True, many=True ) - edition_type = serializers.SerializerMethodField() + edition_type = serializers.ListField( + child=serializers.CharField(allow_null=True), required=False, allow_empty=True + ) language = serializers.ListField( child=serializers.CharField(allow_null=True), required=False, allow_empty=True ) @@ -84,11 +86,6 @@ class Meta: "place_of_publication", ] - def get_edition_type(self, obj) -> list["str"]: - edition_type_str = obj.get("edition_type", None) - edition_types = list(filter(None, edition_type_str.split(","))) - return get_choices_labels(edition_types, Expression.EditionTypes) - class SimpleDetailSerializer(serializers.Serializer): id = serializers.IntegerField() @@ -126,9 +123,21 @@ class RelatedWorksDict(TypedDict): class CharacterDataSerializer(serializers.ModelSerializer): + fictionality = serializers.ListField( + child=serializers.CharField(allow_null=True), required=False, allow_empty=True + ) + class Meta: model = Character - exclude = ["self_contenttype", "data_source"] + fields = [ + "forename", + "surname", + "fallback_name", + "alternative_name", + "description", + "relevancy", + "fictionality", + ] class ArchiveDataSerializer(serializers.ModelSerializer): diff --git a/apis_ontology/api/views.py b/apis_ontology/api/views.py index cc19a86..de0ca4a 100644 --- a/apis_ontology/api/views.py +++ b/apis_ontology/api/views.py @@ -219,7 +219,7 @@ def get_queryset(self): title="title", subtitle="subtitle", edition="edition", - edition_type="edition_type", + edition_type="new_edition_type", language="language", publication_date="publication_date_iso_formatted", publisher="publisher", @@ -324,7 +324,7 @@ def get_queryset(self): title="title", subtitle="subtitle", edition="edition", - edition_type="edition_type", + edition_type="new_edition_type", language="language", publication_date="publication_date_iso_formatted", publisher="publisher", @@ -342,7 +342,7 @@ def get_queryset(self): surname="surname", fallback_name="fallback_name", relevancy="relevancy", - fictionality="fictionality", + fictionality="new_fictionality", ) ) diff --git a/apis_ontology/migrations/0077_remove_character_fictionality_and_more.py b/apis_ontology/migrations/0077_remove_character_fictionality_and_more.py new file mode 100644 index 0000000..46abcd7 --- /dev/null +++ b/apis_ontology/migrations/0077_remove_character_fictionality_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.15 on 2024-09-02 09:07 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("apis_ontology", "0076_migrate_multiselectfield_data_to_arrayfields"), + ] + + operations = [ + migrations.RemoveField( + model_name="character", + name="fictionality", + ), + migrations.RemoveField( + model_name="expression", + name="edition_type", + ), + migrations.RemoveField( + model_name="versioncharacter", + name="fictionality", + ), + migrations.RemoveField( + model_name="versionexpression", + name="edition_type", + ), + ] diff --git a/apis_ontology/models.py b/apis_ontology/models.py index 62ed4a2..31051b8 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -12,7 +12,6 @@ from django.core.validators import validate_slug from django.db import models from django.utils.translation import gettext_lazy as _ -from multiselectfield import MultiSelectField logger = logging.getLogger(__name__) @@ -667,16 +666,6 @@ class EditionTypes(models.TextChoices): help_text=_('Eingabe muss im Format "X-Y" erfolgen, z.B. 5-12'), ) - edition_type = MultiSelectField( - max_length=255, - choices=EditionTypes.choices, - blank=True, - default="", - editable=False, - verbose_name=_("Ausgabetyp (deprecated)"), - help_text=_("Zur Markierung speziell relevanter Ausgaben"), - ) - new_edition_type = ArrayField( base_field=models.CharField( max_length=255, @@ -912,16 +901,6 @@ class CharacterFictionality(models.TextChoices): help_text=_("Bedeutsamkeit für den Text, Erzählfokus"), ) - fictionality = MultiSelectField( - max_length=255, - choices=CharacterFictionality.choices, - blank=False, - default="", - editable=False, - verbose_name=_("Erfindungsgrad (deprecated)"), - help_text=_("Faktizität vs. Fiktionalität"), - ) - new_fictionality = ArrayField( base_field=models.CharField( max_length=255, From ba92465144a75c23dc99f6d004550212b877af09 Mon Sep 17 00:00:00 2001 From: KK Date: Mon, 2 Sep 2024 11:35:29 +0200 Subject: [PATCH 2/2] refactor(models,filters,forms,tables,api): rename ArrayFields Remove 'new_' prefix from names of Expression and Character entity ArrayFields so their names match those of the MultiSelectFields they replaced. --- apis_ontology/api/views.py | 6 ++-- apis_ontology/filtersets.py | 6 ++-- apis_ontology/forms.py | 8 ++--- ...onality_character_fictionality_and_more.py | 32 +++++++++++++++++++ apis_ontology/models.py | 4 +-- apis_ontology/tables.py | 6 ++-- 6 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 apis_ontology/migrations/0078_rename_new_fictionality_character_fictionality_and_more.py diff --git a/apis_ontology/api/views.py b/apis_ontology/api/views.py index de0ca4a..cc19a86 100644 --- a/apis_ontology/api/views.py +++ b/apis_ontology/api/views.py @@ -219,7 +219,7 @@ def get_queryset(self): title="title", subtitle="subtitle", edition="edition", - edition_type="new_edition_type", + edition_type="edition_type", language="language", publication_date="publication_date_iso_formatted", publisher="publisher", @@ -324,7 +324,7 @@ def get_queryset(self): title="title", subtitle="subtitle", edition="edition", - edition_type="new_edition_type", + edition_type="edition_type", language="language", publication_date="publication_date_iso_formatted", publisher="publisher", @@ -342,7 +342,7 @@ def get_queryset(self): surname="surname", fallback_name="fallback_name", relevancy="relevancy", - fictionality="new_fictionality", + fictionality="fictionality", ) ) diff --git a/apis_ontology/filtersets.py b/apis_ontology/filtersets.py index 745f5b5..139c575 100644 --- a/apis_ontology/filtersets.py +++ b/apis_ontology/filtersets.py @@ -200,14 +200,14 @@ class PersonFilterSet(BaseEntityFilterSet, PersonSearch): class CharacterFilterSet(BaseEntityFilterSet, PersonSearch): - new_fictionality = django_filters.MultipleChoiceFilter( + fictionality = django_filters.MultipleChoiceFilter( choices=Character.CharacterFictionality.choices, lookup_expr="icontains", ) class Meta(BaseEntityFilterSet.Meta): fields = { - "new_fictionality": ["icontains"], + "fictionality": ["icontains"], } @@ -279,7 +279,7 @@ class VersionWorkFilterSet(WorkFilterSet): class ExpressionFilterSet(BaseEntityFilterSet, LanguageMixinFilter, TitlesSearch): - new_edition_type = django_filters.MultipleChoiceFilter( + edition_type = django_filters.MultipleChoiceFilter( choices=Expression.EditionTypes.choices, lookup_expr="icontains", ) diff --git a/apis_ontology/forms.py b/apis_ontology/forms.py index b1edc5e..77b0420 100644 --- a/apis_ontology/forms.py +++ b/apis_ontology/forms.py @@ -71,16 +71,16 @@ class WorkForm(GenericModelForm, LanguageForm): class ExpressionForm(GenericModelForm, LanguageForm): - new_edition_type = forms.MultipleChoiceField( + edition_type = forms.MultipleChoiceField( required=False, choices=Expression.EditionTypes.choices, - label=Expression._meta.get_field("new_edition_type").verbose_name, + label=Expression._meta.get_field("edition_type").verbose_name, ) class CharacterForm(GenericModelForm): - new_fictionality = forms.MultipleChoiceField( + fictionality = forms.MultipleChoiceField( required=False, choices=Character.CharacterFictionality.choices, - label=Character._meta.get_field("new_fictionality").verbose_name, + label=Character._meta.get_field("fictionality").verbose_name, ) diff --git a/apis_ontology/migrations/0078_rename_new_fictionality_character_fictionality_and_more.py b/apis_ontology/migrations/0078_rename_new_fictionality_character_fictionality_and_more.py new file mode 100644 index 0000000..b08772f --- /dev/null +++ b/apis_ontology/migrations/0078_rename_new_fictionality_character_fictionality_and_more.py @@ -0,0 +1,32 @@ +# Generated by Django 4.2.15 on 2024-09-02 09:34 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("apis_ontology", "0077_remove_character_fictionality_and_more"), + ] + + operations = [ + migrations.RenameField( + model_name="character", + old_name="new_fictionality", + new_name="fictionality", + ), + migrations.RenameField( + model_name="expression", + old_name="new_edition_type", + new_name="edition_type", + ), + migrations.RenameField( + model_name="versioncharacter", + old_name="new_fictionality", + new_name="fictionality", + ), + migrations.RenameField( + model_name="versionexpression", + old_name="new_edition_type", + new_name="edition_type", + ), + ] diff --git a/apis_ontology/models.py b/apis_ontology/models.py index 31051b8..eeff1d3 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -666,7 +666,7 @@ class EditionTypes(models.TextChoices): help_text=_('Eingabe muss im Format "X-Y" erfolgen, z.B. 5-12'), ) - new_edition_type = ArrayField( + edition_type = ArrayField( base_field=models.CharField( max_length=255, choices=EditionTypes.choices, @@ -901,7 +901,7 @@ class CharacterFictionality(models.TextChoices): help_text=_("Bedeutsamkeit für den Text, Erzählfokus"), ) - new_fictionality = ArrayField( + fictionality = ArrayField( base_field=models.CharField( max_length=255, choices=CharacterFictionality.choices, diff --git a/apis_ontology/tables.py b/apis_ontology/tables.py index b3e1319..222eb5f 100644 --- a/apis_ontology/tables.py +++ b/apis_ontology/tables.py @@ -91,11 +91,11 @@ class ExpressionTable(FullTitleMixin, BaseEntityTable, tables.Table): class Meta(BaseEntityTable.Meta): model = Expression fields = [ - "new_edition_type", + "edition_type", "publication_date_iso_formatted", "publication_date_manual_input", ] - order_by = ("full_title", "publication_date_iso_formatted", "new_edition_type") + order_by = ("full_title", "publication_date_iso_formatted", "edition_type") publication_date_iso_formatted = tables.Column(verbose_name=_("Datum (ISO)")) publication_date_manual_input = tables.Column(verbose_name=_("Datum (manuell)")) @@ -126,7 +126,7 @@ class Meta(BaseEntityTable.Meta): class CharacterTable(FullNameMixin, BaseEntityTable): class Meta(BaseEntityTable.Meta): model = Character - fields = ["relevancy", "new_fictionality"] + fields = ["relevancy", "fictionality"] class MetaCharacterTable(BaseEntityTable):