Documents
* add get document route * add missing attributes to intervention detail view
This commit is contained in:
@@ -60,6 +60,7 @@ class Document(BaseResource):
|
||||
"""
|
||||
Documents can be attached to compensation or intervention for uploading legal documents or pictures.
|
||||
"""
|
||||
title = models.CharField(max_length=500, null=True, blank=True)
|
||||
date_of_creation = models.DateField()
|
||||
document = models.FileField()
|
||||
comment = models.TextField()
|
||||
|
||||
@@ -20,7 +20,7 @@ from simple_sso.sso_client.client import Client
|
||||
|
||||
from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete
|
||||
from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG
|
||||
from konova.views import logout_view, home_view
|
||||
from konova.views import logout_view, home_view, get_document_view
|
||||
|
||||
sso_client = Client(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
|
||||
urlpatterns = [
|
||||
@@ -34,6 +34,7 @@ urlpatterns = [
|
||||
path('organisation/', include("organisation.urls")),
|
||||
path('user/', include("user.urls")),
|
||||
path('news/', include("news.urls")),
|
||||
path('document/<id>', get_document_view, name="doc-open"),
|
||||
|
||||
# Autocomplete paths
|
||||
path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"),
|
||||
|
||||
@@ -7,11 +7,12 @@ Created on: 16.11.20
|
||||
"""
|
||||
from django.contrib.auth import logout
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import redirect, render
|
||||
from django.http import HttpRequest, FileResponse
|
||||
from django.shortcuts import redirect, render, get_object_or_404
|
||||
from django.utils import timezone
|
||||
|
||||
from konova.contexts import BaseContext
|
||||
from konova.models import Document
|
||||
from news.models import ServerMessage
|
||||
from konova.settings import SSO_SERVER_BASE
|
||||
|
||||
@@ -63,3 +64,17 @@ def home_view(request: HttpRequest):
|
||||
}
|
||||
context = BaseContext(request, additional_context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
def get_document_view(request: HttpRequest, id: str):
|
||||
""" Returns a document as downloadable attachment
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
doc = get_object_or_404(Document, id=id)
|
||||
return FileResponse(doc.file, as_attachment=True)
|
||||
|
||||
Reference in New Issue
Block a user