Skip to content

Commit

Permalink
fix: removes reversion plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sennierer committed Mar 4, 2024
1 parent 4b890c4 commit da54c4f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 49 deletions.
45 changes: 3 additions & 42 deletions apis_core/apis_entities/serializers_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.db.models.query import QuerySet
from django.urls import reverse
from rest_framework import serializers
from reversion.models import Version


base_uri = getattr(settings, "APIS_BASE_URI", "http://apis.info")
Expand Down Expand Up @@ -39,25 +38,6 @@ class EntitySerializer(serializers.Serializer):
id = serializers.IntegerField()
url = serializers.SerializerMethodField(method_name="add_url")
uris = EntityUriSerializer(source="uri_set", many=True)
revisions = serializers.SerializerMethodField(method_name="add_revisions")

def add_revisions(self, obj):
ver = Version.objects.get_for_object(obj)
res = []
for v in ver:
usr_1 = getattr(v.revision, "user", None)
if usr_1 is not None:
usr_1 = usr_1.username
else:
usr_1 = "Not specified"
res.append(
{
"id": v.id,
"date_created": v.revision.date_created,
"user_created": usr_1,
}
)
return res

def add_relations(self, obj):
res = {}
Expand Down Expand Up @@ -163,25 +143,6 @@ class RelationEntitySerializer(serializers.Serializer):
start_date_written = serializers.DateField()
end_date_written = serializers.DateField()
relation_type = serializers.SerializerMethodField(method_name="add_relation_label")
revisions = serializers.SerializerMethodField(method_name="add_revisions")

def add_revisions(self, obj):
ver = Version.objects.get_for_object(obj)
res = []
for v in ver:
usr_1 = getattr(v.revision, "user", None)
if usr_1 is not None:
usr_1 = usr_1.username
else:
usr_1 = "Not specified"
res.append(
{
"id": v.id,
"date_created": v.revision.date_created,
"user_created": usr_1,
}
)
return res

def add_entity(self, obj):
return EntitySerializer(
Expand All @@ -192,9 +153,9 @@ def add_relation_label(self, obj):
cm = obj.__class__.__name__
res_1 = dict()
res_1["id"] = obj.relation_type.pk
res_1[
"url"
] = f"{base_uri}{reverse('apis_core:apis_api:{}relation-detail'.format(cm).lower(), kwargs={'pk': obj.relation_type.pk},)}"
res_1["url"] = (
f"{base_uri}{reverse('apis_core:apis_api:{}relation-detail'.format(cm).lower(), kwargs={'pk': obj.relation_type.pk},)}"
)
if self.reverse and len(obj.relation_type.label_reverse) > 0:
res_1["label"] = obj.relation_type.label_reverse
elif self.reverse:
Expand Down
4 changes: 0 additions & 4 deletions apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import reversion
from django.conf import settings
from django.contrib.auth.models import Group
from django.contrib.contenttypes.models import ContentType
Expand All @@ -20,7 +19,6 @@
NEXT_PREV = getattr(settings, "APIS_NEXT_PREV", True)


@reversion.register()
class RootObject(GenericModel, models.Model):
"""
The very root thing that can exist in a given ontology. Several classes inherit from it.
Expand Down Expand Up @@ -89,7 +87,6 @@ def duplicate(self):
duplicate.alters_data = True


@reversion.register()
class Collection(GenericModel, models.Model):
"""Allows to group entities and relation."""

Expand Down Expand Up @@ -147,7 +144,6 @@ def get_queryset(self):
return UriQuerySet(self.model)


@reversion.register()
class Uri(GenericModel, models.Model):
uri = models.URLField(blank=True, null=True, unique=True, max_length=255)
domain = models.CharField(max_length=255, blank=True)
Expand Down
13 changes: 10 additions & 3 deletions apis_core/apis_relations/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unicodedata
import copy

import reversion
from crum import get_current_request
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
Expand All @@ -15,6 +14,7 @@
from apis_core.apis_metainfo.models import RootObject
from apis_core.utils import DateParser
from apis_core.apis_metainfo import signals
from apis_core.apis_history.models import VersionMixin


def find_if_user_accepted():
Expand Down Expand Up @@ -46,7 +46,6 @@ def filter_for_user(self):
return self.get_queryset()


@reversion.register(follow=["rootobject_ptr"])
class Property(RootObject):
class Meta:
verbose_name_plural = "Properties"
Expand Down Expand Up @@ -221,7 +220,7 @@ class InheritanceForeignKey(models.ForeignKey):
forward_related_accessor_class = InheritanceForwardManyToOneDescriptor


class Triple(GenericModel, models.Model):
class Triple(GenericModel, VersionMixin):
subj = InheritanceForeignKey(
RootObject,
blank=True,
Expand Down Expand Up @@ -250,6 +249,14 @@ class Triple(GenericModel, models.Model):
objects = BaseRelationManager()
objects_inheritance = InheritanceManager()

# @property
# def _history_date(self):
# return self.__history_date

# @_history_date.setter
# def _history_date(self, value):
# self.__history_date = value

def __repr__(self):
if self.subj is not None or self.obj is not None or self.prop is not None:
return f"<{self.__class__.__name__}: subj: {self.subj}, prop: {self.prop}, obj: {self.obj}>"
Expand Down

0 comments on commit da54c4f

Please sign in to comment.