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
This commit is contained in:
parent
d203046666
commit
63b2d3ef66
@ -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,
|
||||
|
@ -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
|
||||
|
@ -42,11 +42,9 @@
|
||||
{% fa5_icon 'edit' %}
|
||||
</button>
|
||||
</a>
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Delete' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
</a>
|
||||
<button class="btn btn-default btn-modal" data-form-url="{% url 'intervention:remove' intervention.id %}" title="{% trans 'Delete' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
Binary file not shown.
@ -324,7 +324,7 @@ msgstr "Ökokonto Abbuchungen"
|
||||
|
||||
#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:13
|
||||
msgid "Add new withdraw"
|
||||
msgstr ""
|
||||
msgstr "Neue Abbuchung hinzufügen"
|
||||
|
||||
#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:28
|
||||
msgid "Account Identifier"
|
||||
|
Loading…
Reference in New Issue
Block a user