From 3ac824efbb8fd1f76943fc1985456078cc08797e Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Thu, 11 Apr 2024 11:16:59 +0200 Subject: [PATCH] refactor(apis_metainfo)!: drop Collection model --- apis_core/apis_entities/autocomplete3.py | 6 +--- .../apis_entities/serializers_generic.py | 7 ----- apis_core/apis_entities/test_models.py | 3 -- apis_core/apis_metainfo/admin.py | 3 +- apis_core/apis_metainfo/models.py | 30 ------------------- apis_core/utils/test_caching.py | 1 - 6 files changed, 2 insertions(+), 48 deletions(-) diff --git a/apis_core/apis_entities/autocomplete3.py b/apis_core/apis_entities/autocomplete3.py index a0b9e250e..9efdd7820 100644 --- a/apis_core/apis_entities/autocomplete3.py +++ b/apis_core/apis_entities/autocomplete3.py @@ -10,7 +10,6 @@ from django.core.exceptions import FieldError from django.db.models import Q -from apis_core.apis_metainfo.models import Collection from apis_core.utils.caching import get_autocomplete_property_choices from apis_core.utils.settings import get_entity_settings_by_modelname @@ -76,10 +75,7 @@ class GenericNetworkEntitiesAutocomplete(autocomplete.Select2ListView): def get(self, request, *args, **kwargs): entity = self.kwargs["entity"] q = self.q - if q.startswith("cl:"): - res = Collection.objects.filter(name__icontains=q[3:]) - results = [{"id": "cl:" + str(x.pk), "text": x.name} for x in res] - elif q.startswith("reg:"): + if q.startswith("reg:"): results = [] if entity.lower() == "person": filen = "reg_persons.json" diff --git a/apis_core/apis_entities/serializers_generic.py b/apis_core/apis_entities/serializers_generic.py index 94e94a670..4eb3e72b5 100644 --- a/apis_core/apis_entities/serializers_generic.py +++ b/apis_core/apis_entities/serializers_generic.py @@ -12,11 +12,6 @@ base_uri = base_uri[:-1] -class CollectionSerializer(serializers.Serializer): - id = serializers.IntegerField() - name = serializers.CharField() - - class VocabsSerializer(serializers.Serializer): id = serializers.IntegerField() name = serializers.CharField() @@ -123,8 +118,6 @@ def __init__( for f in inst._meta.many_to_many: if f.name.endswith("relationtype_set"): continue - elif f.name == "collection": - self.fields["collection"] = CollectionSerializer(many=True) self.fields["entity_type"] = serializers.SerializerMethodField( method_name="add_entity_type" ) diff --git a/apis_core/apis_entities/test_models.py b/apis_core/apis_entities/test_models.py index 504a31d47..0e09bdc3e 100644 --- a/apis_core/apis_entities/test_models.py +++ b/apis_core/apis_entities/test_models.py @@ -4,8 +4,6 @@ from rest_framework.test import APIClient from django.contrib.auth.models import Permission -from apis_core.apis_metainfo.models import Collection - class PermissionsModelTestCase(TestCase): name = "test name" @@ -17,7 +15,6 @@ class PermissionsModelTestCase(TestCase): @classmethod def setUpTestData(cls): # Set up data for the whole TestCase - cls.col = Collection.objects.create(name=cls.col_name) cls.user = User.objects.create_user("testuser", "apisdev16") pe = Permission.objects.get(name="Can change person") cls.user.user_permissions.add(pe) diff --git a/apis_core/apis_metainfo/admin.py b/apis_core/apis_metainfo/admin.py index fe341e121..2bfb67fcc 100644 --- a/apis_core/apis_metainfo/admin.py +++ b/apis_core/apis_metainfo/admin.py @@ -1,6 +1,5 @@ from django.contrib import admin -from .models import Collection, Uri +from .models import Uri -admin.site.register(Collection) admin.site.register(Uri) diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index ea1ed7ef0..23b042775 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -1,5 +1,4 @@ from django.conf import settings -from django.contrib.auth.models import Group from django.contrib.contenttypes.models import ContentType from django.db import models from django.db.models.fields.related import ForeignKey, ManyToManyField @@ -78,35 +77,6 @@ def duplicate(self): duplicate.alters_data = True -class Collection(GenericModel, models.Model): - """Allows to group entities and relation.""" - - name = models.CharField(max_length=255) - description = models.TextField(blank=True) - groups_allowed = models.ManyToManyField(Group) - parent_class = models.ForeignKey( - "self", blank=True, null=True, on_delete=models.CASCADE - ) - published = models.BooleanField(default=False) - - @classmethod - def from_db(cls, db, field_names, values): - instance = super().from_db(db, field_names, values) - instance._loaded_values = dict(zip(field_names, values)) - return instance - - def __str__(self): - return self.name - - def save(self, *args, **kwargs): - if hasattr(self, "_loaded_values"): - if self.published != self._loaded_values["published"]: - for ent in self.tempentityclass_set.all(): - ent.published = self.published - ent.save() - super().save(*args, **kwargs) - - class InheritanceForwardManyToOneDescriptor(ForwardManyToOneDescriptor): def get_queryset(self, **hints): return self.field.remote_field.model.objects_inheritance.db_manager( diff --git a/apis_core/utils/test_caching.py b/apis_core/utils/test_caching.py index a0e04af63..6daf26716 100644 --- a/apis_core/utils/test_caching.py +++ b/apis_core/utils/test_caching.py @@ -4,7 +4,6 @@ all_class_modules_and_names = { "apis_metainfo": [ - "Collection", "RootObject", "Uri", ],