Skip to content

Commit

Permalink
refactor: replace caching
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed May 29, 2024
1 parent 782b5c8 commit 2f2f73d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 154 deletions.
116 changes: 0 additions & 116 deletions apis_core/apis_entities/management/commands/serialize_to_json.py

This file was deleted.

29 changes: 8 additions & 21 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from django.urls import reverse
from django.db.models.query import QuerySet

from apis_core.utils import caching
from apis_core.apis_metainfo.models import RootObject
from apis_core.apis_metainfo.models import RootObject, Uri
from apis_core.apis_relations.models import TempTriple
from apis_core.apis_entities import signals

Expand Down Expand Up @@ -199,22 +198,10 @@ def get_serialization(self):


@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
# leads to firing the `post_save` signal
# (https://github.com/etianen/django-reversion/issues/936) - a workaround
# is to check for the raw argument
if not raw:
from apis_core.apis_metainfo.models import Uri

if kwargs["created"] and sender in caching.get_all_ontology_classes():
if BASE_URI.endswith("/"):
base1 = BASE_URI[:-1]
else:
base1 = BASE_URI
uri_c = "{}{}".format(
base1,
reverse("GetEntityGenericRoot", kwargs={"pk": instance.pk}),
)
uri2 = Uri(uri=uri_c, domain="apis default", root_object=instance)
uri2.save()
def create_default_uri(sender, instance, created, raw, using, update_fields, **kwargs):
if getattr(settings, "CREATE_DEFAULT_URI", True):
if isinstance(instance, AbstractEntity) and created:
base = BASE_URI.strip("/")
route = reverse("GetEntityGenericRoot", kwargs={"pk": instance.pk})
uri = f"{base}{route}"
Uri.objects.create(uri=uri, domain="apis default", root_object=instance)
17 changes: 0 additions & 17 deletions apis_core/apis_entities/templatetags/apis_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from operator import itemgetter
from django import template
from apis_core.utils import caching
from apis_core.utils.helpers import triple_sidebar
from django.contrib.contenttypes.models import ContentType
from apis_core.apis_entities.models import AbstractEntity
Expand All @@ -16,21 +14,6 @@ def url_replace(request, field, value):
return dict_.urlencode()


@register.simple_tag
def entities_list_links():
"""
Retrieve all models which inherit from AbstractEntity class
and return their class name and verbose name.
"""
entities_classes = caching.get_all_entity_classes() or []
entities_links = [
(e.__name__.lower(), e._meta.verbose_name.title()) for e in entities_classes
]
entities_links.sort(key=itemgetter(1))

return entities_links


def is_entity(content_type: ContentType):
model_class = content_type.model_class()
return model_class is not None and issubclass(model_class, AbstractEntity)
Expand Down

0 comments on commit 2f2f73d

Please sign in to comment.