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
							
								
									6d48b35107
								
							
						
					
					
						commit
						78d6feabb6
					
				@ -26,9 +26,9 @@ def index_view(request: HttpRequest):
 | 
				
			|||||||
        A rendered view
 | 
					        A rendered view
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    template = "generic_index.html"
 | 
					    template = "generic_index.html"
 | 
				
			||||||
    user = request.user
 | 
					 | 
				
			||||||
    compensations = Compensation.objects.filter(
 | 
					    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(
 | 
					    table = CompensationTable(
 | 
				
			||||||
        request=request,
 | 
					        request=request,
 | 
				
			||||||
 | 
				
			|||||||
@ -143,13 +143,9 @@ class Intervention(BaseObject):
 | 
				
			|||||||
            )
 | 
					            )
 | 
				
			||||||
            for com in coms:
 | 
					            for com in coms:
 | 
				
			||||||
                com.deleted = action
 | 
					                com.deleted = action
 | 
				
			||||||
                #com.deleted_on = _now
 | 
					 | 
				
			||||||
                #com.deleted_by = _user
 | 
					 | 
				
			||||||
                com.save()
 | 
					                com.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.deleted = action
 | 
					            self.deleted = action
 | 
				
			||||||
            #self.deleted_on = _now
 | 
					 | 
				
			||||||
            #self.deleted_by = _user
 | 
					 | 
				
			||||||
            self.save()
 | 
					            self.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
 | 
				
			|||||||
@ -42,11 +42,9 @@
 | 
				
			|||||||
                        {% fa5_icon 'edit' %}
 | 
					                        {% fa5_icon 'edit' %}
 | 
				
			||||||
                    </button>
 | 
					                    </button>
 | 
				
			||||||
                </a>
 | 
					                </a>
 | 
				
			||||||
                <a href="{% url 'home' %}" class="mr-2">
 | 
					                <button class="btn btn-default btn-modal" data-form-url="{% url 'intervention:remove' intervention.id %}" title="{% trans 'Delete' %}">
 | 
				
			||||||
                    <button class="btn btn-default" title="{% trans 'Delete' %}">
 | 
					 | 
				
			||||||
                    {% fa5_icon 'trash' %}
 | 
					                    {% fa5_icon 'trash' %}
 | 
				
			||||||
                </button>
 | 
					                </button>
 | 
				
			||||||
                </a>
 | 
					 | 
				
			||||||
                {% endif %}
 | 
					                {% endif %}
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@ from intervention.models import Intervention
 | 
				
			|||||||
from intervention.tables import InterventionTable
 | 
					from intervention.tables import InterventionTable
 | 
				
			||||||
from konova.contexts import BaseContext
 | 
					from konova.contexts import BaseContext
 | 
				
			||||||
from konova.decorators import *
 | 
					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
 | 
					from konova.utils.message_templates import FORM_INVALID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -190,21 +190,14 @@ def remove_view(request: HttpRequest, id: str):
 | 
				
			|||||||
    Returns:
 | 
					    Returns:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    template = "konova/form.html"
 | 
					 | 
				
			||||||
    obj = Intervention.objects.get(id=id)
 | 
					    obj = Intervention.objects.get(id=id)
 | 
				
			||||||
 | 
					    identifier = obj.identifier
 | 
				
			||||||
    # ToDo
 | 
					    form = RemoveModalForm(request.POST or None, instance=obj, user=request.user)
 | 
				
			||||||
 | 
					    return form.process_request(
 | 
				
			||||||
    form = RemoveForm(
 | 
					        request,
 | 
				
			||||||
        object_to_remove=obj,
 | 
					        _("{} removed").format(identifier),
 | 
				
			||||||
        remove_post_url=reverse("intervention:remove", args=(id,)),
 | 
					        redirect_url=reverse("intervention:index")
 | 
				
			||||||
        cancel_url=reverse("intervention:index"),
 | 
					 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    context = {
 | 
					 | 
				
			||||||
        "form": form,
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    context = BaseContext(request, context).context
 | 
					 | 
				
			||||||
    return render(request, template, context)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@login_required
 | 
					@login_required
 | 
				
			||||||
 | 
				
			|||||||
@ -200,7 +200,7 @@ class RemoveModalForm(BaseModalForm):
 | 
				
			|||||||
            # If the class does not provide restorable delete functionality, we must delete the entry finally
 | 
					            # If the class does not provide restorable delete functionality, we must delete the entry finally
 | 
				
			||||||
            self.instance.delete()
 | 
					            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
 | 
					        """ Generic processing of request
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Wraps the request processing logic, so we don't need the same code everywhere a RemoveModalForm is being used
 | 
					        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:
 | 
					        Returns:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					        redirect_url = redirect_url if redirect_url is not None else request.META.get("HTTP_REFERER", "home")
 | 
				
			||||||
        template = self.template
 | 
					        template = self.template
 | 
				
			||||||
        if request.method == "POST":
 | 
					        if request.method == "POST":
 | 
				
			||||||
            if self.is_valid():
 | 
					            if self.is_valid():
 | 
				
			||||||
@ -221,13 +222,13 @@ class RemoveModalForm(BaseModalForm):
 | 
				
			|||||||
                    request,
 | 
					                    request,
 | 
				
			||||||
                    msg_success
 | 
					                    msg_success
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                return redirect(request.META.get("HTTP_REFERER", "home"))
 | 
					                return redirect(redirect_url)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                messages.info(
 | 
					                messages.info(
 | 
				
			||||||
                    request,
 | 
					                    request,
 | 
				
			||||||
                    msg_error
 | 
					                    msg_error
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                return redirect(request.META.get("HTTP_REFERER", "home"))
 | 
					                return redirect(redirect_url)
 | 
				
			||||||
        elif request.method == "GET":
 | 
					        elif request.method == "GET":
 | 
				
			||||||
            context = {
 | 
					            context = {
 | 
				
			||||||
                "form": self,
 | 
					                "form": self,
 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,6 @@ Created on: 17.11.20
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
import uuid
 | 
					import uuid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.contrib.auth.models import User
 | 
					 | 
				
			||||||
from django.contrib.gis.db.models import MultiPolygonField
 | 
					from django.contrib.gis.db.models import MultiPolygonField
 | 
				
			||||||
from django.db import models
 | 
					from django.db import models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -35,8 +34,6 @@ class BaseResource(UuidModel):
 | 
				
			|||||||
    A basic resource model, which defines attributes for every derived model
 | 
					    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 = 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:
 | 
					    class Meta:
 | 
				
			||||||
        abstract = True
 | 
					        abstract = True
 | 
				
			||||||
@ -51,8 +48,6 @@ class BaseObject(BaseResource):
 | 
				
			|||||||
    identifier = models.CharField(max_length=1000, null=True, blank=True)
 | 
					    identifier = models.CharField(max_length=1000, null=True, blank=True)
 | 
				
			||||||
    title = 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 = 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)
 | 
					    comment = models.TextField(null=True, blank=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class Meta:
 | 
					    class Meta:
 | 
				
			||||||
 | 
				
			|||||||
										
											Binary file not shown.
										
									
								
							@ -324,7 +324,7 @@ msgstr "Ökokonto Abbuchungen"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:13
 | 
					#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:13
 | 
				
			||||||
msgid "Add new withdraw"
 | 
					msgid "Add new withdraw"
 | 
				
			||||||
msgstr ""
 | 
					msgstr "Neue Abbuchung hinzufügen"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:28
 | 
					#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:28
 | 
				
			||||||
msgid "Account Identifier"
 | 
					msgid "Account Identifier"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user