Skip to content

Commit

Permalink
refactor(apis_vocabularies)!: remove apis_vocabularies model
Browse files Browse the repository at this point in the history
This removes the `apis_vocabularies` app- it is not being used right now
and it will be reindtroduced in #441.
The commit removes the app and all references to it from other apps.
We drop the whole `apis_vocabularies` Django app - but because there are
still references from other apps migrations to this apps migrations and
to clean up existing databases, we don't remove the whole module, but
still ship the migrations.

BREAKING CHANGE: projects will have to remove
`apis_core.apis_vocabularies` from the list of INSTALLED_APPS

Closes: #514
  • Loading branch information
b1rger committed Dec 22, 2023
1 parent 0aafcbc commit 1b5f6a4
Show file tree
Hide file tree
Showing 30 changed files with 132 additions and 830 deletions.
36 changes: 2 additions & 34 deletions apis_core/api_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,6 @@ def add_uri(self, obj):
)
)

@extend_schema_field(OpenApiTypes.OBJECT)
def add_type(self, obj):
lst_type = ["kind", "type", "collection_type", "relation_type"]
lst_kind = [
x
for x in obj._meta.fields
if x.name in lst_type and "apis_vocabularies" in str(x.related_model)
]
if len(lst_kind):
pk_obj = getattr(obj, f"{lst_kind[0].name}_id")
if pk_obj is not None:
obj_type = getattr(obj, str(lst_kind[0].name))
res = {
"id": pk_obj,
"url": self.context["view"].request.build_absolute_uri(
reverse(
f"apis:apis_api:{lst_kind[0].related_model.__name__.lower()}-detail",
kwargs={"pk": pk_obj},
)
),
"type": obj_type.__class__.__name__,
"label": str(obj_type),
"parent_class": getattr(obj, "parent_class_id", None),
}
return res

class Meta:
model = TempEntityClass
fields = ["id", "label", "url"]
Expand Down Expand Up @@ -138,10 +112,6 @@ class Meta(ApisBaseSerializer.Meta):
]


class VocabsBaseSerializer(LabelSerializer, EntitySerializer):
pass


class RelatedTripleSerializer(ApisBaseSerializer):
relation_type = serializers.SerializerMethodField(
method_name="add_related_property"
Expand Down Expand Up @@ -196,9 +166,7 @@ def generic_serializer_creation_factory():
lst_cont = caching.get_all_contenttype_classes()
not_allowed_filter_fields = [
"useradded",
"vocab_name",
"parent_class",
"vocab",
"entity",
"autofield",
]
Expand Down Expand Up @@ -272,7 +240,7 @@ def __init__(self, *args, **kwargs):
"ManyToManyField",
"ForeignKey",
"InheritanceForeignKey",
] and "apis_vocabularies" not in str(f.related_model):
]:
self.fields[f.name] = ApisBaseSerializer(
many=ck_many, read_only=True
)
Expand Down Expand Up @@ -308,7 +276,7 @@ def __init__(self, *args, **kwargs):
elif f.__class__.__name__ in [
"ManyToManyField",
"ForeignKey",
] and "apis_vocabularies" not in str(f.related_model):
]:
self.fields[f.name] = ApisBaseSerializer(
many=ck_many, read_only=True
)
Expand Down
45 changes: 0 additions & 45 deletions apis_core/apis_entities/autocomplete3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from django.db.models import Q

from apis_core.apis_metainfo.models import Uri, Collection
from apis_core.apis_vocabularies.models import VocabsBaseClass
from apis_core.utils import caching
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 @@ -377,50 +376,6 @@ def get(self, request, *args, **kwargs):
)


# TODO RDF: Check if this should be removed or adapted
class GenericVocabulariesAutocomplete(autocomplete.Select2ListView):
def get(self, request, *args, **kwargs):
page_size = 20
offset = (int(self.request.GET.get("page", 1)) - 1) * page_size
more = False
vocab = self.kwargs["vocab"]
direct = self.kwargs["direct"]
q = self.q
vocab_model = ContentType.objects.get(
app_label="apis_vocabularies", model=vocab
).model_class()
if direct == "normal":
if vocab_model.__bases__[0] == VocabsBaseClass:
choices = [
{"id": x.pk, "text": x.label}
for x in vocab_model.objects.filter(name__icontains=q).order_by(
"parent_class__name", "name"
)[offset : offset + page_size]
]
else:
choices = [
{"id": x.pk, "text": x.label}
for x in vocab_model.objects.filter(
Q(name__icontains=q) | Q(name_reverse__icontains=q)
).order_by("parent_class__name", "name")[
offset : offset + page_size
]
]
elif direct == "reverse":
choices = [
{"id": x.pk, "text": x.label_reverse}
for x in vocab_model.objects.filter(
Q(name__icontains=q) | Q(name_reverse__icontains=q)
).order_by("parent_class__name", "name")[offset : offset + page_size]
]
if len(choices) == page_size:
more = True
return http.HttpResponse(
json.dumps({"results": choices + [], "pagination": {"more": more}}),
content_type="application/json",
)


# TODO RDF: Check if this should be removed or adapted
class GenericNetworkEntitiesAutocomplete(autocomplete.Select2ListView):
def get(self, request, *args, **kwargs):
Expand Down
34 changes: 0 additions & 34 deletions apis_core/apis_entities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,43 +95,9 @@ def __init__(self, *args, **kwargs):
"apis_entities",
"apis_metainfo",
"apis_relations",
"apis_vocabularies",
],
model=model_uri,
)
if (
len(matching_content_type) == 1
and matching_content_type[0].app_label.lower()
== "apis_vocabularies"
):
self.fields[f].widget = widget1(
url=reverse(
"apis:apis_vocabularies:generic_vocabularies_autocomplete",
kwargs={"vocab": model_uri, "direct": "normal"},
),
attrs=attrs,
)
if self.instance:
res = []
if isinstance(self.fields[f], ModelMultipleChoiceField):
try:
for x in getattr(self.instance, f).all():
res.append((x.pk, x.label))
except ValueError:
pass
self.fields[f].initial = res
self.fields[f].choices = res
else:
try:
res = getattr(self.instance, f)
if res is not None:
self.fields[f].initial = (res.pk, res.label)
self.fields[f].choices = [
(res.pk, res.label),
]
except ValueError:
res = ""

main_fields.append(f)

def sort_fields_list(field_names, entity_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from apis_core.apis_entities.api_renderers import EntityToCIDOC
from apis_core.apis_entities.serializers_generic import EntitySerializer
from apis_core.apis_vocabularies.api_renderers import VocabToSkos
from apis_core.apis_vocabularies.serializers import GenericVocabsSerializer
from apis_core.utils import caching

map_ct = {
Expand Down
13 changes: 0 additions & 13 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,6 @@ def save(self, parse_dates=True, *args, **kwargs):
return self


def prepare_fields_dict(fields_list, vocabs, vocabs_m2m):
res = dict()
for f in fields_list:
res[f["name"]] = getattr(models, f["field_type"])(**f["attributes"])
for v in vocabs:
res[v] = models.ForeignKey(
f"apis_vocabularies.{v}", blank=True, null=True, on_delete=models.SET_NULL
)
for v2 in vocabs_m2m:
res[v2] = models.ManyToManyField(f"apis_vocabularies.{v2}", blank=True)
return res


@receiver(post_save, dispatch_uid="create_default_uri")
def create_default_uri(sender, instance, raw, **kwargs):
# with django reversion, browsing deleted entries in the admin interface
Expand Down
8 changes: 0 additions & 8 deletions apis_core/apis_entities/serializers_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,11 @@ def __init__(
"FloatField",
]:
self.fields[f.name] = getattr(serializers, field_name)()
elif field_name in ["ForeignKey", "ManyToMany"]:
if str(f.related_model.__module__).endswith("apis_vocabularies.models"):
many = False
if f.many_to_many or f.one_to_many:
many = True
self.fields[f.name] = VocabsSerializer(many=many)
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)
elif str(f.related_model.__module__).endswith("apis_vocabularies.models"):
self.fields[f.name] = VocabsSerializer(many=True)
self.fields["entity_type"] = serializers.SerializerMethodField(
method_name="add_entity_type"
)
Expand Down
2 changes: 1 addition & 1 deletion apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from apis_core.apis_metainfo import signals

# from apis_core.apis_entities.serializers_generic import EntitySerializer
# from apis_core.apis_vocabularies.models import CollectionType, LabelType, TextType

path_ac_settings = getattr(settings, "APIS_AUTOCOMPLETE_SETTINGS", False)
if path_ac_settings:
Expand Down Expand Up @@ -111,6 +110,7 @@ def duplicate(self):
@reversion.register()
class Collection(models.Model):
"""Allows to group entities and relation."""

name = models.CharField(max_length=255)
description = models.TextField(blank=True)
groups_allowed = models.ManyToManyField(Group)
Expand Down
19 changes: 0 additions & 19 deletions apis_core/apis_relations/rel_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,6 @@ def __init__(self, *args, **kwargs):
),
),
)
elif (
ContentType.objects.filter(
app_label="apis_vocabularies", model=current_model_name
).count()
> 0
):
self.filters[x] = django_filters.ModelMultipleChoiceFilter(
field_name=x,
queryset=current_qs,
widget=autocomplete.ModelSelect2Multiple(
url=reverse(
"apis:apis_vocabularies:generic_vocabularies_autocomplete",
kwargs={
"vocab": current_model_name,
"direct": "normal",
},
),
),
)
if type(self.filters[x].field).__name__ == "DateField":
self.filters[x] = django_filters.DateFromToRangeFilter(
field_name=x,
Expand Down
Empty file.
75 changes: 0 additions & 75 deletions apis_core/apis_vocabularies/admin.py

This file was deleted.

Loading

0 comments on commit 1b5f6a4

Please sign in to comment.