From 2fca34789fe7c6761c89439f8171b75e605a2193 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Thu, 21 Sep 2023 12:48:17 +0200 Subject: [PATCH] feat(core): add a view for listing reversion version information This commit adds a view to list versions overall or versions specific to an instance. It also links to that view from the generic detail view of the entities. --- .../detail_views/detail_generic.html | 3 +++ .../templates/reversion/version_list.html | 9 ++++++++ apis_core/core/views.py | 21 +++++++++++++++++++ apis_core/urls.py | 4 ++++ 4 files changed, 37 insertions(+) create mode 100644 apis_core/core/templates/reversion/version_list.html create mode 100644 apis_core/core/views.py diff --git a/apis_core/apis_entities/templates/apis_entities/detail_views/detail_generic.html b/apis_core/apis_entities/templates/apis_entities/detail_views/detail_generic.html index 121686a83..b8a6e7c18 100644 --- a/apis_core/apis_entities/templates/apis_entities/detail_views/detail_generic.html +++ b/apis_core/apis_entities/templates/apis_entities/detail_views/detail_generic.html @@ -70,6 +70,9 @@

content_copy {% endif %} + | + history + {% endif %} {% endblock object-actions %} diff --git a/apis_core/core/templates/reversion/version_list.html b/apis_core/core/templates/reversion/version_list.html new file mode 100644 index 000000000..0d9bbee9f --- /dev/null +++ b/apis_core/core/templates/reversion/version_list.html @@ -0,0 +1,9 @@ +{% extends basetemplate %} + +{% block content %} + +{% endblock content %} diff --git a/apis_core/core/views.py b/apis_core/core/views.py new file mode 100644 index 000000000..6f8dce065 --- /dev/null +++ b/apis_core/core/views.py @@ -0,0 +1,21 @@ +from django.views.generic.list import ListView +from django.contrib.contenttypes.models import ContentType +from reversion.models import Revision, Version + + +class Versions(ListView): + paginate_by = 100 + model = Version + instance = None + + def dispatch(self, request, *args, **kwargs): + if content_type := kwargs.get("content_type"): + contenttype = ContentType.objects.get_for_id(content_type) + if object_id := kwargs.get("object_id"): + self.instance = contenttype.model_class().objects.get(pk=object_id) + return super().dispatch(request, *args, **kwargs) + + def get_queryset(self): + if self.instance: + return Version.objects.get_for_object(self.instance) + return Version.objects.all() diff --git a/apis_core/urls.py b/apis_core/urls.py index 13402e075..d60220660 100644 --- a/apis_core/urls.py +++ b/apis_core/urls.py @@ -10,6 +10,8 @@ from apis_core.api_routers import load_additional_serializers from apis_core.api_routers import views +from apis_core.core.views import Versions + # from apis_core.apis_entities.api_views import ( # NetJsonViewSet, # PlaceGeoJsonViewSet, @@ -185,6 +187,8 @@ def build_apis_mock_request(method, path, view, original_request, **kwargs): ), # url(r'^docs/', include('sphinxdoc.urls')), # url(r'^accounts/', include('registration.backends.simple.urls')), + path('reversion/versions/', Versions.as_view(), name="versions"), + path('reversion/versions//', Versions.as_view(), name="versions"), ] if "apis_highlighter" in settings.INSTALLED_APPS: