Skip to content

Commit

Permalink
#334 Move delete_dependency to admin and review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
viliambalaz committed Mar 27, 2021
1 parent b0453ca commit b7d68e0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
13 changes: 12 additions & 1 deletion chcemvediet/apps/inforequests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 0 additions & 13 deletions chcemvediet/apps/inforequests/models/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 []
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
<p>Outbound messages will be deleted:</p>
<ul>{{ outbound|unordered_list }}</ul>
Expand All @@ -27,10 +28,15 @@
<p><label><input name="snooze" type="checkbox" /> Extend snooze of previous action by {{ ADMIN_EXTEND_SNOOZE_BY_DAYS }} days from today.</label></p>
{% endprepend %}
{% endif %}
{% if object.delete_dependency %}
<p><b>Info:</b> Delete not allowed.</p>
<ul>{{ object.delete_dependency|unordered_list }}</ul>
{% delete path=".//form" %}
{% if delete_dependency %}
{% before path=".//form" %}
<p class="errornote">Delete not allowed.</p>
<ul>{{ delete_dependency|unordered_list }}</ul>
{% endbefore %}
{% delete path=".//form//input[@type='submit']" %}
{% after path=".//form//input[@name='post']" %}
<input type="submit" value="{% trans "Yes, I'm sure" %}" disabled/>
{% endafter %}
{% endif %}
{% endamend %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block content %}
{% amend %}
{{ block.super }}
{% after path="./ul[1]" %}
{% after path="./ul[last()]" %}
{% if outbound %}
<p>Outbound messages will be deleted:</p>
<ul>{{ outbound|unordered_list }}</ul>
Expand Down

0 comments on commit b7d68e0

Please sign in to comment.