Skip to content

Commit

Permalink
#334 Allow admin bulk delete on Branch model (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
viliambalaz authored Jun 29, 2021
1 parent e07bf76 commit fd5df3b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
25 changes: 25 additions & 0 deletions chcemvediet/apps/inforequests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ class BranchAdmin(DeleteNestedInforequestEmailAdminMixin, admin.ModelAdmin):
inlines = [
ActionInline,
]
actions = [
u'delete_selected'
]

def get_queryset(self, request):
queryset = super(BranchAdmin, self).get_queryset(request)
Expand All @@ -328,6 +331,28 @@ def render_delete_form(self, request, context):
context[u'delete_constraints'] = self.delete_constraints([context[u'object']])
return super(BranchAdmin, self).render_delete_form(request, context)

@decorate(short_description=u'Delete selected branches')
@transaction.atomic
def delete_selected(self, request, queryset):
outbound, inbound = self.nested_inforequestemail_queryset(queryset)
if request.POST.get(u'post'):
if self.delete_constraints(queryset):
raise PermissionDenied

template_response = delete_selected(self, request, queryset)

if request.POST.get(u'post'):
outbound.delete()
inbound.update(type=InforequestEmail.TYPES.UNDECIDED)
return None

template_response.context_data.update({
u'outbound': [admin_obj_format(inforequestemail) for inforequestemail in outbound],
u'inbound': [admin_obj_format(inforequestemail) for inforequestemail in inbound],
u'delete_constraints': self.delete_constraints(queryset),
})
return template_response

def delete_model(self, request, obj):
if self.delete_constraints([obj]):
raise PermissionDenied
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "admin/delete_selected_confirmation.html" %}
{% load amend before after set_attributes from poleno.amend %}

{% block content %}
{% amend %}
{{ block.super }}
{% after path="./ul[last()]" %}
{% if outbound %}
<p>The following outbound messages will be deleted:</p>
<ul>{{ outbound|unordered_list }}</ul>
{% endif %}
{% if inbound %}
<p>The following inbound messages will be marked undecided:</p>
<ul>{{ inbound|unordered_list }}</ul>
{% endif %}
{% endafter %}
{% before path=".//form//input[@type='submit']" %}
{% if delete_constraints %}
<div class="errornote">
<p>Delete not allowed.</p>
<ul>{{ delete_constraints|unordered_list }}</ul>
</div>
{% set_attributes path=".//form//input[@type='submit']" disabled=True %}
{% endif %}
{% endbefore %}
{% endamend %}
{% endblock %}

0 comments on commit fd5df3b

Please sign in to comment.