Documents removing
* adds document removing button * adds translation * adds Document admin
This commit is contained in:
@@ -7,7 +7,7 @@ Created on: 22.07.21
|
||||
"""
|
||||
from django.contrib import admin
|
||||
|
||||
from konova.models import Geometry
|
||||
from konova.models import Geometry, Document
|
||||
|
||||
|
||||
class GeometryAdmin(admin.ModelAdmin):
|
||||
@@ -18,4 +18,15 @@ class GeometryAdmin(admin.ModelAdmin):
|
||||
]
|
||||
|
||||
|
||||
class DocumentAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"title",
|
||||
"comment",
|
||||
"created_on",
|
||||
"created_by",
|
||||
]
|
||||
|
||||
|
||||
admin.site.register(Geometry, GeometryAdmin)
|
||||
admin.site.register(Document, DocumentAdmin)
|
||||
|
||||
@@ -132,7 +132,7 @@ a {
|
||||
.btn-default{
|
||||
color: white;
|
||||
background-color: var(--rlp-red);
|
||||
border-radius: 0;
|
||||
border-radius: 0.15rem;
|
||||
}
|
||||
.btn-default:hover{
|
||||
/*
|
||||
|
||||
@@ -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, get_document_view
|
||||
from konova.views import logout_view, home_view, get_document_view, new_document_view, remove_document_view
|
||||
|
||||
sso_client = Client(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
|
||||
urlpatterns = [
|
||||
@@ -34,7 +34,11 @@ urlpatterns = [
|
||||
path('organisation/', include("organisation.urls")),
|
||||
path('user/', include("user.urls")),
|
||||
path('news/', include("news.urls")),
|
||||
|
||||
# Documents
|
||||
path('document/<id>', get_document_view, name="doc-open"),
|
||||
path('document/new', new_document_view, name="doc-new"),
|
||||
path('document/<id>/remove>', remove_document_view, name="doc-remove"),
|
||||
|
||||
# Autocomplete paths
|
||||
path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"),
|
||||
|
||||
@@ -5,11 +5,13 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 16.11.20
|
||||
|
||||
"""
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import logout
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest, FileResponse
|
||||
from django.shortcuts import redirect, render, get_object_or_404
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.contexts import BaseContext
|
||||
from konova.models import Document
|
||||
@@ -66,6 +68,7 @@ def home_view(request: HttpRequest):
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
def get_document_view(request: HttpRequest, id: str):
|
||||
""" Returns a document as downloadable attachment
|
||||
|
||||
@@ -77,4 +80,41 @@ def get_document_view(request: HttpRequest, id: str):
|
||||
|
||||
"""
|
||||
doc = get_object_or_404(Document, id=id)
|
||||
return FileResponse(doc.file, as_attachment=True)
|
||||
return FileResponse(doc.document, as_attachment=True)
|
||||
|
||||
|
||||
@login_required
|
||||
def new_document_view(request: HttpRequest):
|
||||
""" Renders a form for uploading new documents
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
template = ""
|
||||
# TODO
|
||||
context = {}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
def remove_document_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
doc = get_object_or_404(Document, id=id)
|
||||
title = doc.title
|
||||
#doc.delete()
|
||||
messages.success(
|
||||
request,
|
||||
_("Document '{}' deleted").format(title)
|
||||
)
|
||||
return redirect(request.META.get("HTTP_REFERER", "home"))
|
||||
|
||||
Reference in New Issue
Block a user