Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!(apis_metainfo): drop Collection model #774

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions apis_core/apis_entities/autocomplete3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_entities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions apis_core/apis_entities/serializers_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
)
Expand Down
3 changes: 0 additions & 3 deletions apis_core/apis_entities/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions apis_core/apis_metainfo/admin.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions apis_core/apis_metainfo/migrations/0013_delete_collection.py
Original file line number Diff line number Diff line change
@@ -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",
),
]
30 changes: 0 additions & 30 deletions apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion apis_core/utils/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

all_class_modules_and_names = {
"apis_metainfo": [
"Collection",
"RootObject",
"Uri",
],
Expand Down
Loading