Skip to content

Commit

Permalink
#311 Admin delete InforequestEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
viliambalaz committed Nov 22, 2020
1 parent d8f3ff1 commit daa51c6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chcemvediet/apps/inforequests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ def get_queryset(self, request):
queryset = queryset.select_related(u'email')
return queryset

def has_delete_permission(self, request, obj=None):
return obj.has_delete_permission if obj else True

@admin.register(Branch, site=admin.site)
class BranchAdmin(NoBulkDeleteAdminMixin, DeleteNestedInforequestEmailAdminMixin, admin.ModelAdmin):
date_hierarchy = None
Expand Down
12 changes: 12 additions & 0 deletions chcemvediet/apps/inforequests/models/inforequestemail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# vim: expandtab
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from aggregate_if import Count

Expand Down Expand Up @@ -72,6 +73,14 @@ class Meta:
[u'type', u'inforequest'],
]

@cached_property
def has_delete_permission(self):
try:
action = self.email.action
return action not in Action.objects.of_inforequest(inforequest=self.inforequest)
except Action.DoesNotExist:
return True

def __unicode__(self):
return format(self.pk)

Expand All @@ -95,3 +104,6 @@ def datachecks(superficial, autofix):
issues = [u'; '.join(issues)]
for issue in issues:
yield datacheck.Error(issue + u'.')

# Must be after ``InforequestEmail`` to break cyclic dependency
from .action import Action
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "admin/change_form.html" %}
{% load amend prepend from poleno.amend %}

{% block content %}
{% amend %}
{{ block.super }}
{% if not original.has_delete_permission %}
{% prepend path='.//div[@class="submit-row"]' %}
<p class="deletelink-box">Email is dependent on:
<a href="{% url 'admin:inforequests_action_change' original.email.action.pk %}">
&lt;Action: {{ original.email.action.pk }}&gt;
</a>
</p>
{% endprepend %}
{% endif %}
{% endamend %}
{% endblock %}

0 comments on commit daa51c6

Please sign in to comment.