diff --git a/apis_core/apis_entities/serializers_generic.py b/apis_core/apis_entities/serializers_generic.py index b3eae5019..6d34732b2 100644 --- a/apis_core/apis_entities/serializers_generic.py +++ b/apis_core/apis_entities/serializers_generic.py @@ -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") @@ -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 = {} @@ -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( @@ -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: diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index f8377aec8..e7cd4aa59 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -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 @@ -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. @@ -89,7 +87,6 @@ def duplicate(self): duplicate.alters_data = True -@reversion.register() class Collection(GenericModel, models.Model): """Allows to group entities and relation.""" @@ -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) diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index e4b332d31..e07552ed9 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -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 @@ -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(): @@ -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" @@ -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, @@ -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}>"