From 98ef91e04494058a6424c24fb8c8d213d1bdf4ae 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 Closes: #576 --- apis_core/apis_entities/autocomplete3.py | 6 +--- apis_core/apis_entities/models.py | 6 ---- apis_core/apis_entities/serializers.py | 1 - .../apis_entities/serializers_generic.py | 7 ----- apis_core/apis_entities/test_models.py | 3 -- apis_core/apis_metainfo/admin.py | 3 +- .../migrations/0013_delete_collection.py | 15 ++++++++++ apis_core/apis_metainfo/models.py | 30 ------------------- apis_core/utils/test_caching.py | 1 - 9 files changed, 17 insertions(+), 55 deletions(-) create mode 100644 apis_core/apis_metainfo/migrations/0013_delete_collection.py 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/models.py b/apis_core/apis_entities/models.py index 645ecd4cb..7703843fa 100644 --- a/apis_core/apis_entities/models.py +++ b/apis_core/apis_entities/models.py @@ -174,12 +174,6 @@ def merge_with(self, entities): e_b = type(ent).__name__ if e_a != e_b: continue - # TODO: if collections are removed, remove this as well - if hasattr(ent, "collection"): - col_list = list(self.collection.all()) - for col2 in ent.collection.all(): - if col2 not in col_list: - self.collection.add(col2) for f in ent._meta.local_many_to_many: if not f.name.endswith("_set"): sl = list(getattr(self, f.name).all()) diff --git a/apis_core/apis_entities/serializers.py b/apis_core/apis_entities/serializers.py index 60453eb15..191d1099b 100644 --- a/apis_core/apis_entities/serializers.py +++ b/apis_core/apis_entities/serializers.py @@ -168,7 +168,6 @@ def to_representation(self, obj): "data": dict(), } r["data"]["uri"] = [x.uri for x in obj.uri_set.all()] - r["data"]["collections"] = [x.name for x in obj.collection.all()] r["data"]["notes"] = obj.notes r["data"]["references"] = obj.references r["data"]["start_date"] = obj.start_date_written diff --git a/apis_core/apis_entities/serializers_generic.py b/apis_core/apis_entities/serializers_generic.py index 6d34732b2..751feb6b2 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/migrations/0013_delete_collection.py b/apis_core/apis_metainfo/migrations/0013_delete_collection.py new file mode 100644 index 000000000..385c3e030 --- /dev/null +++ b/apis_core/apis_metainfo/migrations/0013_delete_collection.py @@ -0,0 +1,15 @@ +# Generated by Django 4.2.10 on 2024-04-11 09:26 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("apis_metainfo", "0012_remove_rootobject_deprecated_name"), + ] + + operations = [ + migrations.DeleteModel( + name="Collection", + ), + ] 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", ],