Skip to content

Commit

Permalink
#334 Refactor Branch admin deleting (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
viliambalaz authored Apr 27, 2021
1 parent 6794f32 commit 2b4c37a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 12 additions & 4 deletions chcemvediet/apps/inforequests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,18 @@ def get_queryset(self, request):
def get_inforequest(self, obj):
return obj.inforequest

def has_delete_permission(self, request, obj=None):
if obj is None:
return True
return not obj.is_main
def delete_constraints(self, obj):
if obj.is_main:
return [format_html(u'{} is main.'.format(admin_obj_format(obj)))]

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)

def delete_model(self, request, obj):
if self.delete_constraints(obj):
raise PermissionDenied
return super(BranchAdmin, self).delete_model(request, obj)

@admin.register(Action, site=admin.site)
class ActionAdmin(NoBulkDeleteAdminMixin, DeleteNestedInforequestEmailAdminMixin, admin.ModelAdmin):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "admin/delete_confirmation.html" %}
{% load amend after from poleno.amend %}
{% load amend before after set_attributes from poleno.amend %}

{% block content %}
{% amend %}
Expand All @@ -14,5 +14,14 @@
<ul>{{ inbound|unordered_list }}</ul>
{% endif %}
{% endafter %}
{% if delete_constraints %}
{% before path=".//form" %}
<div class="errornote">
<p>Delete not allowed.</p>
<ul>{{ delete_constraints|unordered_list }}</ul>
</div>
{% endbefore %}
{% set_attributes path=".//form//input[@type='submit']" disabled=False %}
{% endif %}
{% endamend %}
{% endblock %}

0 comments on commit 2b4c37a

Please sign in to comment.