Skip to content

Commit

Permalink
#334 Use set_attributes tag to disable submit button
Browse files Browse the repository at this point in the history
  • Loading branch information
viliambalaz committed Apr 15, 2021
1 parent ea700b4 commit 1896e84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions chcemvediet/apps/inforequests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def get_queryset(self, request):
def get_inforequest(self, obj):
return obj.branch.inforequest

def delete_dependency(self, obj):
def delete_constraints(self, obj):
dependency = []
if obj.type in [Action.TYPES.REQUEST, Action.TYPES.ADVANCED_REQUEST]:
dependency.append(format_html(
Expand All @@ -387,12 +387,12 @@ def delete_dependency(self, obj):
return dependency

def render_delete_form(self, request, context):
context[u'delete_dependency'] = self.delete_dependency(context[u'object'])
context[u'delete_constraints'] = self.delete_constraints(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 self.delete_dependency(obj):
if self.delete_constraints(obj):
raise PermissionDenied
if request.POST:
if (request.POST.get(u'snooze')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "admin/delete_confirmation.html" %}
{% load i18n %}
{% load amend prepend before after delete from poleno.amend %}
{% load amend prepend before after set_attributes from poleno.amend %}

{% block content %}
{% amend %}
Expand Down Expand Up @@ -28,15 +28,14 @@
<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 delete_dependency %}
{% if delete_constraints %}
{% before path=".//form" %}
<p class="errornote">Delete not allowed.</p>
<ul>{{ delete_dependency|unordered_list }}</ul>
<div class="errornote">
<p>Delete not allowed.</p>
<ul>{{ delete_constraints|unordered_list }}</ul>
</div>
{% endbefore %}
{% delete path=".//form//input[@type='submit']" %}
{% after path=".//form//input[@name='post']" %}
<input type="submit" value="{% trans "Yes, I'm sure" %}" disabled/>
{% endafter %}
{% set_attributes path=".//form//input[@type='submit']" disabled=True %}
{% endif %}
{% endamend %}
{% endblock %}

0 comments on commit 1896e84

Please sign in to comment.