From 78d6feabb64f85653931188ba44ca13468f37063 Mon Sep 17 00:00:00 2001 From: mipel Date: Mon, 2 Aug 2021 15:39:33 +0200 Subject: [PATCH] Compensation enhancements * compensations won't be listed in index table if related intervention has been deleted * adds functionality for intervention remove button * adds outcommented code * adds configurable redirect_url for RemoveModalForm's process_request method * adds translation --- compensation/views.py | 4 ++-- intervention/models.py | 4 ---- .../templates/intervention/detail/view.html | 8 +++---- intervention/views.py | 21 ++++++------------ konova/forms.py | 7 +++--- konova/models.py | 5 ----- locale/de/LC_MESSAGES/django.mo | Bin 11030 -> 11090 bytes locale/de/LC_MESSAGES/django.po | 2 +- 8 files changed, 17 insertions(+), 34 deletions(-) diff --git a/compensation/views.py b/compensation/views.py index 55e585ad..2e790206 100644 --- a/compensation/views.py +++ b/compensation/views.py @@ -26,9 +26,9 @@ def index_view(request: HttpRequest): A rendered view """ template = "generic_index.html" - user = request.user compensations = Compensation.objects.filter( - deleted=None, + deleted=None, # only show those which are not deleted individually + intervention__deleted=None, # and don't show the ones whose intervention has been deleted ) table = CompensationTable( request=request, diff --git a/intervention/models.py b/intervention/models.py index 22f68f8c..de61f960 100644 --- a/intervention/models.py +++ b/intervention/models.py @@ -143,13 +143,9 @@ class Intervention(BaseObject): ) for com in coms: com.deleted = action - #com.deleted_on = _now - #com.deleted_by = _user com.save() self.deleted = action - #self.deleted_on = _now - #self.deleted_by = _user self.save() @staticmethod diff --git a/intervention/templates/intervention/detail/view.html b/intervention/templates/intervention/detail/view.html index 49a98ba9..e2668e35 100644 --- a/intervention/templates/intervention/detail/view.html +++ b/intervention/templates/intervention/detail/view.html @@ -42,11 +42,9 @@ {% fa5_icon 'edit' %} - - - + {% endif %} diff --git a/intervention/views.py b/intervention/views.py index 40fbd6a2..9f5d41dc 100644 --- a/intervention/views.py +++ b/intervention/views.py @@ -9,7 +9,7 @@ from intervention.models import Intervention from intervention.tables import InterventionTable from konova.contexts import BaseContext from konova.decorators import * -from konova.forms import RemoveForm, SimpleGeomForm, NewDocumentForm +from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm from konova.utils.message_templates import FORM_INVALID @@ -190,21 +190,14 @@ def remove_view(request: HttpRequest, id: str): Returns: """ - template = "konova/form.html" obj = Intervention.objects.get(id=id) - - # ToDo - - form = RemoveForm( - object_to_remove=obj, - remove_post_url=reverse("intervention:remove", args=(id,)), - cancel_url=reverse("intervention:index"), + identifier = obj.identifier + form = RemoveModalForm(request.POST or None, instance=obj, user=request.user) + return form.process_request( + request, + _("{} removed").format(identifier), + redirect_url=reverse("intervention:index") ) - context = { - "form": form, - } - context = BaseContext(request, context).context - return render(request, template, context) @login_required diff --git a/konova/forms.py b/konova/forms.py index 73dfd391..ea1ba76b 100644 --- a/konova/forms.py +++ b/konova/forms.py @@ -200,7 +200,7 @@ class RemoveModalForm(BaseModalForm): # If the class does not provide restorable delete functionality, we must delete the entry finally self.instance.delete() - def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID): + def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID, redirect_url: str = None): """ Generic processing of request Wraps the request processing logic, so we don't need the same code everywhere a RemoveModalForm is being used @@ -213,6 +213,7 @@ class RemoveModalForm(BaseModalForm): Returns: """ + redirect_url = redirect_url if redirect_url is not None else request.META.get("HTTP_REFERER", "home") template = self.template if request.method == "POST": if self.is_valid(): @@ -221,13 +222,13 @@ class RemoveModalForm(BaseModalForm): request, msg_success ) - return redirect(request.META.get("HTTP_REFERER", "home")) + return redirect(redirect_url) else: messages.info( request, msg_error ) - return redirect(request.META.get("HTTP_REFERER", "home")) + return redirect(redirect_url) elif request.method == "GET": context = { "form": self, diff --git a/konova/models.py b/konova/models.py index 4df4a91a..9db04005 100644 --- a/konova/models.py +++ b/konova/models.py @@ -8,7 +8,6 @@ Created on: 17.11.20 import os import uuid -from django.contrib.auth.models import User from django.contrib.gis.db.models import MultiPolygonField from django.db import models @@ -35,8 +34,6 @@ class BaseResource(UuidModel): A basic resource model, which defines attributes for every derived model """ created = models.ForeignKey(UserActionLogEntry, on_delete=models.SET_NULL, null=True, blank=True, related_name='+') - #created_on = models.DateTimeField(auto_now_add=True, null=True) - #created_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL, related_name="+") class Meta: abstract = True @@ -51,8 +48,6 @@ class BaseObject(BaseResource): identifier = models.CharField(max_length=1000, null=True, blank=True) title = models.CharField(max_length=1000, null=True, blank=True) deleted = models.ForeignKey(UserActionLogEntry, on_delete=models.SET_NULL, null=True, blank=True, related_name='+') - #deleted_on = models.DateTimeField(null=True, blank=True) - #deleted_by = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL, related_name="+") comment = models.TextField(null=True, blank=True) class Meta: diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index cd1378796f0831be3c07aebab7a512706ac9f65e..cfda504466a1e7fd0aa1095ed5d8a0711d94d20b 100644 GIT binary patch delta 3749 zcmYk-2~bs49LMp)rl{~#Krsw?mLiCx;EHC78*Zp+;*JSoxCRO#MqL-kG(`h(Ei{vG zYifqZX~wCvQA-_{vL-9Wa*PSh#%fB<2B+`uz4K8OF^VJlpT;aFiE|F_iwz=k|uns0Xgv`fUuR{x@pGP4;?pTVwb$N&ILa!%+hpiyH7$Y=_zQdNH=3 zz8cluMpQqQ*pB{9t-awBRD)k2f94`TYUpRw$nTv_}+FQW$XBPxZBr~x*iW*$zfvNLMN zJ#9S&S!!#UGo~0H!_C+MYwh(DsE)rwHFyV= z`Xg6K{4Fx2%Z)Bxj96CHqB%2bDf9!N*sIMdd1QK>3KJy2rLm!Sq&fm-`RsDU0w zZPH6vjdxJbmvgf^uEGSYLEZnAJ?}J7PzL@%jX02LDa9eEj6|bS-3`@X4^#uat!X%z z`YcStU8n(HM{TxSsJ-(CYDxY>#%5fklP(?8g@RHs2sP3)REN`0Gn|de%ra{UDq|bb zjXO{seQf;{HGxy8=e|X?cLUX4BWi#Tu%F)l02Vlw69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