Skip to content

Commit

Permalink
feat(core): add a view for listing reversion version information
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Sep 21, 2023
1 parent ce9316f commit 7f2e1d5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apis_core/core/templates/reversion/version_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends basetemplate %}

{% block content %}
<ul>
{% for version in object_list %}
<li>{{version.revision.date_created }} - {{ version.revision.user }}: {{ version.revision.get_comment }}</li>
{% endfor %}
</ul>
{% endblock content %}
21 changes: 21 additions & 0 deletions apis_core/core/views.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions apis_core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/<int:content_type>/<int:object_id>', Versions.as_view(), name="versions"),
]

if "apis_highlighter" in settings.INSTALLED_APPS:
Expand Down

0 comments on commit 7f2e1d5

Please sign in to comment.