Skip to content

Commit

Permalink
refactor(apis_metainfo)!: drop Collection model
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Apr 11, 2024
1 parent ae78620 commit ae32a37
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 48 deletions.
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
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)
16 changes: 16 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,16 @@
# 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

0 comments on commit ae32a37

Please sign in to comment.