diff --git a/apis_core/api_routers.py b/apis_core/api_routers.py index 7c10aacf3..7570601f8 100644 --- a/apis_core/api_routers.py +++ b/apis_core/api_routers.py @@ -20,7 +20,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 @@ -109,7 +108,6 @@ def add_type(self, obj): return res 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 06e707737..d8ac9c9c2 100644 --- a/apis_core/apis_entities/detail_generic.py +++ b/apis_core/apis_entities/detail_generic.py @@ -59,20 +59,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 88403044a..c402173c2 100644 --- a/apis_core/apis_entities/filters.py +++ b/apis_core/apis_entities/filters.py @@ -8,7 +8,6 @@ from django.db.models import Q, JSONField from apis_core.apis_metainfo.models import Collection -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 ( @@ -58,7 +57,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 dd397d25f..975c0a650 100644 --- a/apis_core/apis_entities/forms.py +++ b/apis_core/apis_entities/forms.py @@ -158,70 +158,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 != 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/0001_initial.py b/apis_core/apis_entities/migrations/0001_initial.py index 2586313fc..c107bee02 100644 --- a/apis_core/apis_entities/migrations/0001_initial.py +++ b/apis_core/apis_entities/migrations/0001_initial.py @@ -1,7 +1,6 @@ # Generated by Django 3.1.14 on 2022-02-01 12:41 -from django.db import migrations, models -import django.db.models.deletion +from django.db import migrations class Migration(migrations.Migration): @@ -12,65 +11,4 @@ class Migration(migrations.Migration): ("apis_metainfo", "0001_initial"), ] - operations = [ - migrations.CreateModel( - name="TempEntityClass", - fields=[ - ( - "rootobject_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="apis_metainfo.rootobject", - ), - ), - ( - "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( - blank=True, max_length=255, null=True, verbose_name="Start" - ), - ), - ( - "end_date_written", - models.CharField( - blank=True, max_length=255, null=True, verbose_name="End" - ), - ), - ("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)), - ("collection", models.ManyToManyField(to="apis_metainfo.Collection")), - ( - "source", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="apis_metainfo.source", - ), - ), - ("text", models.ManyToManyField(blank=True, to="apis_metainfo.Text")), - ], - options={ - "abstract": False, - }, - bases=("apis_metainfo.rootobject",), - ), - ] + operations = [] diff --git a/apis_core/apis_entities/models.py b/apis_core/apis_entities/models.py index 5703d31be..e572720bf 100644 --- a/apis_core/apis_entities/models.py +++ b/apis_core/apis_entities/models.py @@ -235,103 +235,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 - - def prepare_fields_dict(fields_list, vocabs, vocabs_m2m): res = dict() for f in fields_list: 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/utils/caching.py b/apis_core/utils/caching.py index 8d4a6d568..f9cc56c54 100644 --- a/apis_core/utils/caching.py +++ b/apis_core/utils/caching.py @@ -28,7 +28,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 # from apis_core.apis_vocabularies.models import AbstractVocabulary @@ -75,8 +75,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 f38ee3f9c..fb31b027b 100644 --- a/apis_core/utils/test_caching.py +++ b/apis_core/utils/test_caching.py @@ -14,7 +14,6 @@ "VocabsBaseClass", "VocabsUri", ], - "apis_entities": ["TempEntityClass"], "apis_relations": ["TempTriple", "Property", "Triple"], "contenttypes": ["ContentType"], }