diff --git a/chcemvediet/apps/inforequests/admin.py b/chcemvediet/apps/inforequests/admin.py index c5eaca7d..e4aa8e10 100644 --- a/chcemvediet/apps/inforequests/admin.py +++ b/chcemvediet/apps/inforequests/admin.py @@ -376,12 +376,23 @@ def get_queryset(self, request): def get_inforequest(self, obj): return obj.branch.inforequest + def delete_dependency(self, obj): + dependency = [] + if obj.type in [Action.TYPES.REQUEST, Action.TYPES.ADVANCED_REQUEST]: + dependency.append(format_html( + u'{} is type {}.'.format(admin_obj_format(obj), obj.get_type_display()))) + if len(obj.branch.actions) == 1: + dependency.append(format_html( + u'{} is the only action in the branch.'.format(admin_obj_format(obj)))) + return dependency + def render_delete_form(self, request, context): + context[u'delete_dependency'] = self.delete_dependency(context[u'object']) context[u'ADMIN_EXTEND_SNOOZE_BY_DAYS'] = ADMIN_EXTEND_SNOOZE_BY_DAYS return super(ActionAdmin, self).render_delete_form(request, context) def delete_model(self, request, obj): - if obj.delete_dependency: + if self.delete_dependency(obj): raise PermissionDenied if request.POST: if (request.POST.get(u'snooze') diff --git a/chcemvediet/apps/inforequests/models/action.py b/chcemvediet/apps/inforequests/models/action.py index 892ab3cd..51c81315 100644 --- a/chcemvediet/apps/inforequests/models/action.py +++ b/chcemvediet/apps/inforequests/models/action.py @@ -8,13 +8,11 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.functional import cached_property from django.contrib.contenttypes import generic -from django.utils.html import format_html from aggregate_if import Count from multiselectfield import MultiSelectField from poleno import datacheck from poleno.attachments.models import Attachment -from poleno.utils.admin import admin_obj_format from poleno.workdays import workdays from poleno.utils.models import FieldChoices, QuerySet, join_lookup, after_saved from poleno.utils.date import utc_now, local_today @@ -452,17 +450,6 @@ def deadline(self): raise ValueError(u'Invalid action type: {}'.format(self.type)) - @cached_property - def delete_dependency(self): - dependency = [] - if self.type in [Action.TYPES.REQUEST, Action.TYPES.ADVANCED_REQUEST]: - dependency.append(format_html( - u'{} is type {}.'.format(admin_obj_format(self), self.get_type_display()))) - if len(self.branch.actions) == 1: - dependency.append(format_html( - u'{} is the only action in the branch.'.format(admin_obj_format(self)))) - return dependency - @classmethod def create(cls, *args, **kwargs): advanced_to = kwargs.pop(u'advanced_to', None) or [] diff --git a/chcemvediet/apps/inforequests/templates/admin/inforequests/action/delete_confirmation.html b/chcemvediet/apps/inforequests/templates/admin/inforequests/action/delete_confirmation.html index 198082ee..34032b13 100644 --- a/chcemvediet/apps/inforequests/templates/admin/inforequests/action/delete_confirmation.html +++ b/chcemvediet/apps/inforequests/templates/admin/inforequests/action/delete_confirmation.html @@ -1,10 +1,11 @@ {% extends "admin/delete_confirmation.html" %} +{% load i18n %} {% load amend prepend before after delete from poleno.amend %} {% block content %} {% amend %} {{ block.super }} - {% after path="./ul[1]" %} + {% after path="./ul[last()]" %} {% if outbound %}
Outbound messages will be deleted:
Info: Delete not allowed.
-Delete not allowed.
+Outbound messages will be deleted: