Documents removing

* adds generic modal rendering using package django-bootstrap-modal-forms
* adds document file removing from hard drive
* adds translations
pull/2/head
mipel 3 years ago
parent 47ec30919c
commit 8885f81770

@ -1,7 +1,12 @@
{% extends 'base.html' %}
{% load i18n static fontawesome_5 %}
{% block head %}
{% endblock %}
{% block body %}
<div id="detail-header" class="row">
<div class="col-sm-12 col-md-12 col-lg-6">
<h3>{% trans 'Intervention' %} {{intervention.identifier}}</h3>
@ -293,11 +298,9 @@
</td>
<td class="align-middle">{{ doc.comment }}</td>
<td>
<a href="{% url 'doc-remove' doc.id %}" class="mr-2">
<button class="btn btn-default" title="{% trans 'Remove document' %}">
{% fa5_icon 'trash' %}
</button>
</a>
<button data-form-url="{% url 'doc-remove' doc.id %}" class="btn btn-default del-btn" title="{% trans 'Remove document' %}">
{% fa5_icon 'trash' %}
</button>
</td>
</tr>
{% endfor %}
@ -308,4 +311,8 @@
</div>
</div>
{% with 'del-btn' as btn_class %}
{% include 'modal/modal_form_script.html' %}
{% endwith %}
{% endblock %}

@ -23,6 +23,7 @@ class BaseContext:
"user": None,
"current_role": None,
"help_link": HELP_LINK,
"modal_reload_page": "true", # must be string and lower case true, since it's used in JS code
}
def __init__(self, request: HttpRequest, additional_context: dict = {}):

@ -8,10 +8,12 @@ Created on: 16.11.20
from abc import abstractmethod
from bootstrap_modal_forms.forms import BSModalModelForm, BSModalForm
from django import forms
from django.contrib.auth.models import User
from django.contrib.gis.forms import GeometryField, OSMWidget
from django.contrib.gis.geos import Polygon
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
@ -127,3 +129,18 @@ class SimpleGeomForm(BaseForm):
self.fields["geom"].widget.attrs["default_zoom"] = 1
self.initialize_form_field("geom", geom)
self.area = geom.area
class RemoveDocumentForm(BaseForm, BSModalForm):
confirm = forms.BooleanField(
label=_("Confirm"),
label_suffix=_(""),
widget=forms.CheckboxInput(),
required=True,
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.instance = kwargs.get("instance", None)
self.form_title = _("Remove document")
self.form_caption = _("This will remove '{}'. Are you sure?").format(self.instance.title)

@ -5,6 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 17.11.20
"""
import os
import uuid
from django.contrib.auth.models import User
@ -65,6 +66,19 @@ class Document(BaseResource):
document = models.FileField()
comment = models.TextField()
def delete(self, using=None, keep_parents=False):
""" Custom delete function to remove the real file from the hard drive
Args:
using ():
keep_parents ():
Returns:
"""
os.remove(self.document.file.name)
super().delete(using=using, keep_parents=keep_parents)
class Geometry(BaseResource):
"""

@ -55,6 +55,7 @@ INSTALLED_APPS = [
'django.contrib.gis',
'simple_sso.sso_server',
'django_tables2',
'bootstrap_modal_forms',
'fontawesome_5',
'bootstrap4',
'konova',

@ -38,7 +38,7 @@ urlpatterns = [
# 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"),
path('document/<id>/remove', remove_document_view, name="doc-remove"),
# Autocomplete paths
path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"),

@ -14,6 +14,7 @@ from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from konova.contexts import BaseContext
from konova.forms import RemoveDocumentForm
from konova.models import Document
from news.models import ServerMessage
from konova.settings import SSO_SERVER_BASE
@ -104,17 +105,43 @@ def new_document_view(request: HttpRequest):
def remove_document_view(request: HttpRequest, id: str):
""" Renders a form for uploading new documents
This function works using a modal. We are not using the regular way, the django bootstrap modal forms are
intended to be used. Instead of View classes we work using the classic way of dealing with forms (see below).
It is important to mention, that modal forms, which should reload the page afterwards, must provide a
'reload_page' bool in the context. This way, the modal may reload the page or not.
For further details see the comments in templates/modal or
https://github.com/trco/django-bootstrap-modal-forms
Args:
request (HttpRequest): The incoming request
Returns:
"""
template = "modal/modal_form.html"
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"))
form = RemoveDocumentForm(request.POST or None, instance=doc)
if request.method == "POST":
if form.is_valid():
doc.delete()
messages.success(
request,
_("Document '{}' deleted").format(title)
)
return redirect(request.META.get("HTTP_REFERER", "home"))
else:
messages.info(
request,
_("There was an error on this form.")
)
return redirect(request.META.get("HTTP_REFERER", "home"))
elif request.method == "GET":
context = {
"form": form,
}
context = BaseContext(request, context).context
return render(request, template, context)
else:
raise NotImplementedError

Binary file not shown.

@ -4,14 +4,14 @@
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#: intervention/filters.py:25 intervention/filters.py:31
#: intervention/filters.py:38 intervention/filters.py:39 konova/forms.py:71
#: user/forms.py:38
#: intervention/filters.py:38 intervention/filters.py:39 konova/forms.py:73
#: konova/forms.py:137 user/forms.py:38
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-07-23 16:00+0200\n"
"POT-Creation-Date: 2021-07-23 18:26+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -23,15 +23,15 @@ msgstr ""
#: compensation/tables.py:18 compensation/tables.py:71 intervention/forms.py:26
#: intervention/tables.py:23
#: intervention/templates/intervention/detail-view.html:174
#: intervention/templates/intervention/detail-view.html:179
msgid "Identifier"
msgstr "Kennung"
#: compensation/tables.py:23 compensation/tables.py:76 intervention/forms.py:33
#: intervention/tables.py:28
#: intervention/templates/intervention/detail-view.html:57
#: intervention/templates/intervention/detail-view.html:177
#: intervention/templates/intervention/detail-view.html:276
#: intervention/templates/intervention/detail-view.html:62
#: intervention/templates/intervention/detail-view.html:182
#: intervention/templates/intervention/detail-view.html:281
msgid "Title"
msgstr "Bezeichnung"
@ -44,7 +44,7 @@ msgid "Actions"
msgstr "Aktionen"
#: compensation/tables.py:44
#: intervention/templates/intervention/detail-view.html:154
#: intervention/templates/intervention/detail-view.html:159
msgid "Compensations"
msgstr "Kompensationen"
@ -101,7 +101,7 @@ msgid "Which intervention type is this"
msgstr "Welcher Eingriffstyp"
#: intervention/forms.py:44
#: intervention/templates/intervention/detail-view.html:65
#: intervention/templates/intervention/detail-view.html:70
msgid "Law"
msgstr "Gesetz"
@ -110,7 +110,7 @@ msgid "Based on which law"
msgstr "Basiert auf welchem Recht"
#: intervention/forms.py:50
#: intervention/templates/intervention/detail-view.html:85
#: intervention/templates/intervention/detail-view.html:90
msgid "Intervention handler"
msgstr "Eingriffsverursacher"
@ -159,12 +159,12 @@ msgid "Edit intervention"
msgstr "Eingriff bearbeiten"
#: intervention/tables.py:33
#: intervention/templates/intervention/detail-view.html:89
#: intervention/templates/intervention/detail-view.html:94
msgid "Checked"
msgstr "Geprüft"
#: intervention/tables.py:39
#: intervention/templates/intervention/detail-view.html:103
#: intervention/templates/intervention/detail-view.html:108
msgid "Recorded"
msgstr "Verzeichnet"
@ -181,7 +181,7 @@ msgid "Interventions"
msgstr "Eingriffe"
#: intervention/tables.py:92 intervention/tables.py:170
#: intervention/templates/intervention/detail-view.html:7
#: intervention/templates/intervention/detail-view.html:12
#: konova/templates/konova/home.html:11 templates/navbar.html:22
msgid "Intervention"
msgstr "Eingriff"
@ -210,112 +210,112 @@ msgstr "Für Sie freigegeben - Datensatz kann bearbeitet werden"
msgid "Access not granted"
msgstr "Nicht freigegeben - Datensatz nur lesbar"
#: intervention/templates/intervention/detail-view.html:12
#: intervention/templates/intervention/detail-view.html:17
msgid "Open in LANIS"
msgstr "In LANIS öffnen"
#: intervention/templates/intervention/detail-view.html:17
#: intervention/templates/intervention/detail-view.html:22
msgid "Public report"
msgstr "Öffentlicher Bericht"
#: intervention/templates/intervention/detail-view.html:23
#: intervention/templates/intervention/detail-view.html:28
msgid "Share"
msgstr "Freigabe"
#: intervention/templates/intervention/detail-view.html:28
#: intervention/templates/intervention/detail-view.html:33
msgid "Run check"
msgstr "Prüfung vornehmen"
#: intervention/templates/intervention/detail-view.html:33
#: intervention/templates/intervention/detail-view.html:38
msgid "Record"
msgstr "Verzeichnen"
#: intervention/templates/intervention/detail-view.html:38
#: intervention/templates/intervention/detail-view.html:43
msgid "Edit"
msgstr "Bearbeiten"
#: intervention/templates/intervention/detail-view.html:43
#: intervention/templates/intervention/detail-view.html:48
#: venv/lib/python3.7/site-packages/django/forms/formsets.py:391
msgid "Delete"
msgstr "Löschen"
#: intervention/templates/intervention/detail-view.html:61
#: intervention/templates/intervention/detail-view.html:66
msgid "Process type"
msgstr "Verfahrenstyp"
#: intervention/templates/intervention/detail-view.html:69
#: intervention/templates/intervention/detail-view.html:74
msgid "Registration office"
msgstr "Zulassungsbehörde"
#: intervention/templates/intervention/detail-view.html:73
#: intervention/templates/intervention/detail-view.html:78
msgid "Registration office file number"
msgstr "Aktenzeichen Zulassungsbehörde"
#: intervention/templates/intervention/detail-view.html:77
#: intervention/templates/intervention/detail-view.html:82
msgid "Conservation office"
msgstr "Naturschutzbehörde"
#: intervention/templates/intervention/detail-view.html:81
#: intervention/templates/intervention/detail-view.html:86
msgid "Conversation office file number"
msgstr "Aktenzeichen Naturschutzbehörde"
#: intervention/templates/intervention/detail-view.html:117
#: intervention/templates/intervention/detail-view.html:122
msgid "Registration date"
msgstr "Datum Zulassung bzw. Satzungsbeschluss"
#: intervention/templates/intervention/detail-view.html:121
#: intervention/templates/intervention/detail-view.html:126
msgid "Binding on"
msgstr "Datum Bestandskraft"
#: intervention/templates/intervention/detail-view.html:125
#: intervention/templates/intervention/detail-view.html:130
msgid "Last modified"
msgstr "Zuletzt bearbeitet"
#: intervention/templates/intervention/detail-view.html:129
#: intervention/templates/intervention/detail-view.html:134
msgid "by"
msgstr "von"
#: intervention/templates/intervention/detail-view.html:138
#: intervention/templates/intervention/detail-view.html:143
msgid "No geometry added, yet."
msgstr "Keine Geometrie vorhanden"
#: intervention/templates/intervention/detail-view.html:159
#: intervention/templates/intervention/detail-view.html:164
msgid "Add new compensation"
msgstr "Neue Kompensation hinzufügen"
#: intervention/templates/intervention/detail-view.html:204
#: intervention/templates/intervention/detail-view.html:209
msgid "Payments"
msgstr "Ersatzzahlungen"
#: intervention/templates/intervention/detail-view.html:209
#: intervention/templates/intervention/detail-view.html:214
msgid "Add new payment"
msgstr "Neue Zahlung hinzufügen"
#: intervention/templates/intervention/detail-view.html:224
#: intervention/templates/intervention/detail-view.html:229
msgid "Amount"
msgstr "Betrag"
#: intervention/templates/intervention/detail-view.html:227
#: intervention/templates/intervention/detail-view.html:232
msgid "Transfer comment"
msgstr "Verwendungszweck"
#: intervention/templates/intervention/detail-view.html:256
#: intervention/templates/intervention/detail-view.html:261
msgid "Documents"
msgstr "Dokumente"
#: intervention/templates/intervention/detail-view.html:261
#: intervention/templates/intervention/detail-view.html:266
msgid "Add new document"
msgstr "Neues Dokument hinzufügen"
#: intervention/templates/intervention/detail-view.html:279
#: intervention/templates/intervention/detail-view.html:284
msgid "Comment"
msgstr "Kommentar"
#: intervention/templates/intervention/detail-view.html:282
#: intervention/templates/intervention/detail-view.html:287
msgid "Action"
msgstr "Aktionen"
#: intervention/templates/intervention/detail-view.html:297
#: intervention/templates/intervention/detail-view.html:301 konova/forms.py:145
msgid "Remove document"
msgstr "Dokument löschen"
@ -353,22 +353,26 @@ msgstr "Hierfür müssen Sie Administrator sein!"
msgid "You need to be part of another user group."
msgstr "Hierfür müssen Sie einer anderen Nutzergruppe angehören!"
#: konova/forms.py:44
#: konova/forms.py:46
msgid "Not editable"
msgstr "Nicht editierbar"
#: konova/forms.py:70
#: konova/forms.py:72 konova/forms.py:136
msgid "Confirm"
msgstr "Bestätigen"
msgstr "Bestätige"
#: konova/forms.py:82
#: konova/forms.py:84
msgid "Remove"
msgstr "Entferne"
#: konova/forms.py:84
#: konova/forms.py:86
msgid "You are about to remove {} {}"
msgstr "Sie sind dabei {} {} zu löschen"
#: konova/forms.py:146
msgid "This will remove '{}'. Are you sure?"
msgstr "Hiermit wird '{}' gelöscht. Sind Sie sicher?"
#: konova/management/commands/setup_data.py:42
msgid "On new related data"
msgstr "Wenn neue Daten für mich angelegt werden"
@ -421,11 +425,13 @@ msgstr "Ökokonto"
msgid "Withdraw"
msgstr "Abbuchen"
#: konova/views.py:118
#, fuzzy
#| msgid "Document identifier"
#: konova/views.py:133
msgid "Document '{}' deleted"
msgstr "Aktenzeichen"
msgstr "Dokument '{}' gelöscht"
#: konova/views.py:139
msgid "There was an error on this form."
msgstr "Es gab einen Fehler im Formular."
#: news/templates/news/dashboard-news.html:12 news/templates/news/index.html:19
msgid "Published on"
@ -467,6 +473,10 @@ msgstr "Abbrechen"
msgid "Save"
msgstr "Speichern"
#: templates/modal/modal_form.html:30
msgid "Continue"
msgstr "Weiter"
#: templates/navbar.html:4
msgid "Kompensationsverzeichnis Service Portal"
msgstr ""

@ -4,6 +4,7 @@ certifi==2020.11.8
chardet==3.0.4
Django==3.1.3
django-autocomplete-light==3.8.1
django-bootstrap-modal-forms==2.2.0
django-bootstrap4==3.0.1
django-debug-toolbar==3.1.1
django-filter==2.4.0

@ -8,6 +8,10 @@
{% bootstrap_javascript jquery='full' %}
{% fontawesome_5_static %}
<link rel="stylesheet" href="{% static 'css/konova.css' %}">
{% comment %}
Adds script for modal rendering
{% endcomment %}
<script src="{% static 'js/jquery.bootstrap.modal.forms.min.js' %}"></script>
{% block head %}
{% endblock %}
@ -27,6 +31,15 @@
{% endfor %}
</div>
{% comment %}
The modal wrapper, which can be used on every view can stay on the base.html template
{% endcomment %}
<div class="modal fade" tabindex="-1" role="dialog" id="modal">
<div class="modal-dialog" role="document">
<div class="modal-content"></div>
</div>
</div>
{% block body %}
{% endblock %}

@ -0,0 +1,32 @@
{% load i18n %}
{% comment %}
A generic modal form template which is based on django-bootstrap-modal-forms package
https://pypi.org/project/django-bootstrap-modal-forms/
{% endcomment %}
<form method="post" action="{{form.action_url}}">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title">{{form.form_title}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<article class="mb-5">{{form.form_caption}}</article>
{% for field in form %}
<div class="form-group{% if field.errors %} invalid{% endif %}">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
{% for error in field.errors %}
<p class="help-block">{{ error }}</p>
{% endfor %}
</div>
{% endfor %}
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default">{% trans 'Continue' %}</button>
</div>
</form>

@ -0,0 +1,18 @@
{% comment %}
Taken from https://github.com/trco/django-bootstrap-modal-forms
isDeleteForm refers to reloading the whole page after submitting the form in our case.
{% endcomment %}
<script type="text/javascript">
$(document).ready(function() {
$(".{{btn_class}}").each(function () {
$(this).modalForm({
formURL: $(this).data("form-url"),
isDeleteForm: {{modal_reload_page}},
}
);
});
});
</script>
Loading…
Cancel
Save