diff --git a/apis_core/api_routers.py b/apis_core/api_routers.py index b238fa713..3e211cad6 100644 --- a/apis_core/api_routers.py +++ b/apis_core/api_routers.py @@ -19,7 +19,6 @@ ) from drf_spectacular.types import OpenApiTypes from django_filters import rest_framework as filters -from apis_core.apis_entities.models import TempEntityClass from .api_renderers import NetJsonRenderer from .apis_relations.models import Triple, Property from apis_core.utils import caching @@ -82,7 +81,6 @@ def add_uri(self, obj): ) class Meta: - model = TempEntityClass fields = ["id", "label", "url"] diff --git a/apis_core/apis_entities/detail_generic.py b/apis_core/apis_entities/detail_generic.py index 6a61e5df3..5e823fd2f 100644 --- a/apis_core/apis_entities/detail_generic.py +++ b/apis_core/apis_entities/detail_generic.py @@ -48,20 +48,8 @@ def get(self, request, *args, **kwargs): iiif_info_json = self.instance.name relevant_fields = [] - # those are fields from TempEntityClass, this exclude list can be removed once TempEntityClass is dropped - exclude_fields = [ - "start_date", - "start_start_date", - "start_end_date", - "end_date", - "end_start_date", - "end_end_date", - "tempentityclass_ptr", - "rootobject_ptr", - "collection", - ] entity_settings = get_entity_settings_by_modelname(self.entity) - exclude_fields.extend(entity_settings.get("detail_view_exclude", [])) + exclude_fields = entity_settings.get("detail_view_exclude", []) for field, value in model_to_dict(self.instance).items(): if field not in exclude_fields: relevant_fields.append((self.instance._meta.get_field(field), value)) diff --git a/apis_core/apis_entities/filters.py b/apis_core/apis_entities/filters.py index 0aadcaace..95614d675 100644 --- a/apis_core/apis_entities/filters.py +++ b/apis_core/apis_entities/filters.py @@ -6,7 +6,6 @@ from django.conf import settings from django.db.models import JSONField -from apis_core.apis_entities.models import TempEntityClass from apis_core.utils import caching from apis_core.utils.settings import get_entity_settings_by_modelname from apis_core.utils.filtermethods import ( @@ -55,7 +54,6 @@ class GenericEntityListFilter(django_filters.FilterSet): end_date = django_filters.DateFromToRangeFilter() class Meta: - model = TempEntityClass # exclude all hardcoded fields or nothing, however this exclude is only defined here as a temporary measure in # order to load all filters of all model fields by default so that they are available in the first place. # Later those which are not referenced in the settings file will be removed again diff --git a/apis_core/apis_entities/forms.py b/apis_core/apis_entities/forms.py index 3a8600f74..a94b183e6 100644 --- a/apis_core/apis_entities/forms.py +++ b/apis_core/apis_entities/forms.py @@ -97,70 +97,6 @@ def sort_fields_list(field_names, entity_name): crispy_main_fields.append(Field(field)) self.helper.layout = Layout(crispy_main_fields) - # backwards compatibility: - # those fields are part of TempEntityClass - this - # block can probably be removed when TempEntityClass - # is gone from apis_entities - # for now we at least check if they exist - if "status" in self.fields: - self.fields["status"].required = False - if "collection" in self.fields: - self.fields["collection"].required = False - if "start_date_written" in self.fields: - self.fields["start_date_written"].required = False - if "end_date_written" in self.fields: - self.fields["end_date_written"].required = False - - instance = getattr(self, "instance", None) - if instance is not None: - - # same as above, part of TempEntityClass - if "start_date_written" in self.fields: - if instance.start_date_written: - self.fields[ - "start_date_written" - ].help_text = DateParser.get_date_help_text_from_dates( - single_date=instance.start_date, - single_start_date=instance.start_start_date, - single_end_date=instance.start_end_date, - single_date_written=instance.start_date_written, - ) - else: - self.fields[ - "start_date_written" - ].help_text = DateParser.get_date_help_text_default() - - # same as above, part of TempEntityClass - if "end_date_written" in self.fields: - if instance.end_date_written: - self.fields[ - "end_date_written" - ].help_text = DateParser.get_date_help_text_from_dates( - single_date=instance.end_date, - single_start_date=instance.end_start_date, - single_end_date=instance.end_end_date, - single_date_written=instance.end_date_written, - ) - else: - self.fields[ - "end_date_written" - ].help_text = DateParser.get_date_help_text_default() - - def save(self, *args, **kwargs): - obj = super(GenericEntitiesForm, self).save(*args, **kwargs) - - # backwards compatibility - # collection is a field of TempEntityClass - this block - # can be removed when TempEntityClass is gone from apis_entities - # for now we at least check if the attribute exist - if hasattr(obj, "collection"): - if obj.collection.all().count() == 0: - col_name = getattr( - settings, "APIS_DEFAULT_COLLECTION", "manually created entity" - ) - col, created = Collection.objects.get_or_create(name=col_name) - obj.collection.add(col) - return obj return GenericEntitiesForm diff --git a/apis_core/apis_entities/migrations/0004_delete_tempentityclass.py b/apis_core/apis_entities/migrations/0004_delete_tempentityclass.py new file mode 100644 index 000000000..e6a860b57 --- /dev/null +++ b/apis_core/apis_entities/migrations/0004_delete_tempentityclass.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.8 on 2024-01-09 12:20 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("apis_entities", "0003_remove_tempentityclass_source"), + ] + + operations = [ + migrations.DeleteModel( + name="TempEntityClass", + ), + ] diff --git a/apis_core/apis_entities/models.py b/apis_core/apis_entities/models.py index 3391de792..f37c97188 100644 --- a/apis_core/apis_entities/models.py +++ b/apis_core/apis_entities/models.py @@ -233,103 +233,6 @@ def get_serialization(self): return EntitySerializer(self).data -@reversion.register(follow=["rootobject_ptr"]) -class TempEntityClass(AbstractEntity): - """ - Base class to bind common attributes to many classes. - - The common attributes are: - - written start and enddates, - - recognized start and enddates which are derived from the written dates - using RegEx, - - a review boolean field to mark an object as reviewed. - """ - - review = models.BooleanField( - default=False, - help_text="Should be set to True, if the " - "data record holds up quality " - "standards.", - ) - start_date = models.DateField(blank=True, null=True) - start_start_date = models.DateField(blank=True, null=True) - start_end_date = models.DateField(blank=True, null=True) - end_date = models.DateField(blank=True, null=True) - end_start_date = models.DateField(blank=True, null=True) - end_end_date = models.DateField(blank=True, null=True) - start_date_written = models.CharField( - max_length=255, - blank=True, - null=True, - verbose_name="Start", - ) - end_date_written = models.CharField( - max_length=255, - blank=True, - null=True, - verbose_name="End", - ) - # TODO RDF: Make Text also a Subclass of RootObject - collection = models.ManyToManyField("apis_metainfo.Collection") - status = models.CharField(max_length=100) - references = models.TextField(blank=True, null=True) - notes = models.TextField(blank=True, null=True) - published = models.BooleanField(default=False) - objects = models.Manager() - objects_inheritance = InheritanceManager() - - def __str__(self): - if self.name != "" and hasattr( - self, "first_name" # TODO RDF: remove first_name here - ): # relation usually donĀ“t have names - return "{}, {} (ID: {})".format(self.name, self.first_name, self.id) - elif self.name != "": - return "{} (ID: {})".format(self.name, self.id) - else: - return "(ID: {})".format(self.id) - - def save(self, parse_dates=True, *args, **kwargs): - """ - Adaption of the save() method of the class to automatically parse - string-dates into date objects. - """ - - if parse_dates: - # overwrite every field with None as default - start_date = None - start_start_date = None - start_end_date = None - end_date = None - end_start_date = None - end_end_date = None - - # if some textual user input of a start date is there, parse it - if self.start_date_written: - start_date, start_start_date, start_end_date = DateParser.parse_date( - self.start_date_written - ) - - # if some textual user input of an end date is there, parse it - if self.end_date_written: - end_date, end_start_date, end_end_date = DateParser.parse_date( - self.end_date_written - ) - - self.start_date = start_date - self.start_start_date = start_start_date - self.start_end_date = start_end_date - self.end_date = end_date - self.end_start_date = end_start_date - self.end_end_date = end_end_date - - if self.name: - self.name = unicodedata.normalize("NFC", self.name) - - super(TempEntityClass, self).save(*args, **kwargs) - - return self - - @receiver(post_save, dispatch_uid="create_default_uri") def create_default_uri(sender, instance, raw, **kwargs): # with django reversion, browsing deleted entries in the admin interface diff --git a/apis_core/apis_metainfo/dal_urls.py b/apis_core/apis_metainfo/dal_urls.py deleted file mode 100644 index 695c548b8..000000000 --- a/apis_core/apis_metainfo/dal_urls.py +++ /dev/null @@ -1,13 +0,0 @@ -from django.urls import path - -from . import dal_views - -app_name = "apis_metainfo" - -urlpatterns = [ - path( - "tempentity-autocomplete/", - dal_views.TempEntityClassAC.as_view(), - name="apis_tempentity-autocomplete", - ) -] diff --git a/apis_core/apis_metainfo/dal_views.py b/apis_core/apis_metainfo/dal_views.py deleted file mode 100644 index ce958b857..000000000 --- a/apis_core/apis_metainfo/dal_views.py +++ /dev/null @@ -1,13 +0,0 @@ -from dal import autocomplete - -from apis_core.apis_entities.models import TempEntityClass - - -class TempEntityClassAC(autocomplete.Select2QuerySetView): - def get_queryset(self): - qs = TempEntityClass.objects.all() - - if self.q: - qs = qs.filter(name__icontains=self.q) - - return qs diff --git a/apis_core/apis_metainfo/serializers.py b/apis_core/apis_metainfo/serializers.py index d164dd22a..4740820f2 100644 --- a/apis_core/apis_metainfo/serializers.py +++ b/apis_core/apis_metainfo/serializers.py @@ -2,7 +2,6 @@ from rest_framework import serializers from .models import Collection, Text, Uri -from apis_core.apis_entities.models import TempEntityClass class CollectionSerializer(serializers.HyperlinkedModelSerializer): @@ -56,25 +55,6 @@ class Meta: model = Uri -class TempEntityClassSerializer(serializers.HyperlinkedModelSerializer): - url = serializers.HyperlinkedIdentityField( - view_name="apis:apis_api:tempentityclass-detail", lookup_field="pk" - ) - collection = serializers.HyperlinkedRelatedField( - view_name="apis:apis_api:collection-detail", lookup_field="pk", read_only=True - ) - text = serializers.HyperlinkedRelatedField( - view_name="apis:apis_api:text-detail", lookup_field="pk", read_only=True - ) - source = serializers.HyperlinkedRelatedField( - view_name="apis:apis_api:source-detail", lookup_field="pk", read_only=True - ) - - class Meta: - fields = "__all__" - model = TempEntityClass - - class ContentTypeSerializer(serializers.HyperlinkedModelSerializer): url = serializers.HyperlinkedIdentityField( view_name="apis:apis_api:contenttype-detail", lookup_field="pk" diff --git a/apis_core/urls.py b/apis_core/urls.py index 8db22186d..67b4fe1d8 100644 --- a/apis_core/urls.py +++ b/apis_core/urls.py @@ -70,10 +70,6 @@ "metainfo/", include("apis_core.apis_metainfo.urls", namespace="apis_metainfo"), ), - path( - "metainfo-ac/", - include("apis_core.apis_metainfo.dal_urls", namespace="apis_metainfo-ac"), - ), path( "api/", include((router.urls, "apis_core"), namespace="apis_api") ), # routers do not support namespaces out of the box diff --git a/apis_core/utils/caching.py b/apis_core/utils/caching.py index 19cfc00e9..0e2a7010f 100644 --- a/apis_core/utils/caching.py +++ b/apis_core/utils/caching.py @@ -26,7 +26,7 @@ def _init_all_ontology_classes(): # the imports are done here as this module here might be called before full Django # initialization. Otherwise, it would break. - from apis_core.apis_entities.models import AbstractEntity, TempEntityClass + from apis_core.apis_entities.models import AbstractEntity # from apis_core.apis_relations.models import AbstractReification @@ -66,8 +66,6 @@ def _init_all_ontology_classes(): if ( issubclass(ontology_class, AbstractEntity) and not ontology_class._meta.abstract - and ontology_class - is not TempEntityClass # TODO RDF: remove this once TempEntityClass is removed ): _entity_classes.append(ontology_class) _entity_class_names.append(ontology_class_name.lower()) diff --git a/apis_core/utils/helpers.py b/apis_core/utils/helpers.py index 9ee78834b..a731f7a55 100644 --- a/apis_core/utils/helpers.py +++ b/apis_core/utils/helpers.py @@ -6,7 +6,6 @@ from typing import Type -from apis_core.apis_entities.models import TempEntityClass from apis_core.apis_relations.models import Property, TempTriple from apis_core.utils.settings import get_entity_settings_by_modelname from apis_core.apis_relations.tables import get_generic_triple_table @@ -22,7 +21,7 @@ @functools.lru_cache def get_classes_with_allowed_relation_from( entity_name: str, -) -> list[Type[TempEntityClass]]: +) -> list[object]: """Returns a list of classes to which the given class may be related by a Property""" # Find all the properties where the entity is either subject or object diff --git a/apis_core/utils/test_caching.py b/apis_core/utils/test_caching.py index 04f782c82..9d5752beb 100644 --- a/apis_core/utils/test_caching.py +++ b/apis_core/utils/test_caching.py @@ -8,7 +8,6 @@ "RootObject", "Uri", ], - "apis_entities": ["TempEntityClass"], "apis_relations": ["TempTriple", "Property", "Triple"], "contenttypes": ["ContentType"], }