Skip to content
Snippets Groups Projects
Verified Commit f4d9a990 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add API view for accessing the PDF file of live documents

(cherry picked from commit a43f2d7b)
parent b8a68452
No related branches found
No related tags found
1 merge request!25Prepare release 2.0b1
......@@ -5,6 +5,7 @@ from .views import (
LiveDocumentDeleteView,
LiveDocumentEditView,
LiveDocumentListView,
LiveDocumentShowAPIView,
LiveDocumentShowView,
PosterCurrentView,
PosterDeleteView,
......@@ -42,4 +43,9 @@ urlpatterns = [
path(
"live_documents/<str:slug>.pdf", LiveDocumentShowView.as_view(), name="show_live_document",
),
path(
"api/live_documents/<str:slug>.pdf",
LiveDocumentShowAPIView.as_view(),
name="api_show_live_document",
),
]
......@@ -15,6 +15,7 @@ from django.views.generic.list import ListView
from django_tables2 import SingleTableView
from guardian.shortcuts import get_objects_for_user
from oauth2_provider.views.mixins import ClientProtectedResourceMixin
from reversion.views import RevisionMixin
from rules.contrib.views import PermissionRequiredMixin
......@@ -221,15 +222,24 @@ class LiveDocumentDeleteView(PermissionRequiredMixin, RevisionMixin, AdvancedDel
success_message = _("The live document has been deleted.")
class LiveDocumentShowView(PermissionRequiredMixin, SingleObjectMixin, View):
"""Show the current version of the live document."""
class LiveDocumentShowBaseView(SingleObjectMixin, View):
"""Base view for showing live documents."""
model = LiveDocument
permission_required = "resint.view_livedocument_rule"
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> FileResponse:
live_document = self.get_object()
file = live_document.get_current_file()
if not file:
raise Http404
return FileResponse(file.file, content_type="application/pdf")
return FileResponse(file, content_type="application/pdf")
class LiveDocumentShowView(PermissionRequiredMixin, LiveDocumentShowBaseView):
"""Show the current version of the live document."""
permission_required = "resint.view_livedocument_rule"
class LiveDocumentShowAPIView(ClientProtectedResourceMixin, LiveDocumentShowBaseView):
"""Show the current version of the live document in API."""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment