Skip to content

Commit

Permalink
Redirect to collection listing after deleting an item from it
Browse files Browse the repository at this point in the history
  • Loading branch information
Tijani-Dia committed Jan 10, 2022
1 parent 9b551a9 commit 1e14fe0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
Expand Up @@ -17,6 +17,7 @@
<p>{% trans "Are you sure you want to delete this document?" %}</p>
<form action="{% url 'wagtaildocs:delete' document.id %}" method="POST">
{% csrf_token %}
<input type="hidden" value="{{ next }}" name="next">
<input type="submit" value='{% trans "Yes, delete" %}' class="button serious" />
<a href="{% url 'wagtaildocs:index' %}" class="button button-secondary">{% trans "No, don't delete" %}</a>
</form>
Expand Down
Expand Up @@ -47,7 +47,7 @@
<li>
<input type="submit" value="{% trans 'Save' %}" class="button" />
{% if user_can_delete %}
<a href="{% url 'wagtaildocs:delete' document.id %}" class="button button-secondary no">{% trans "Delete document" %}</a>
<a href="{% url 'wagtaildocs:delete' document.id %}{% if next %}?next={{ next }}{% endif %}" class="button button-secondary no">{% trans "Delete document" %}</a>
{% endif %}
</li>
</ul>
Expand Down
5 changes: 4 additions & 1 deletion wagtail/documents/views/documents.py
Expand Up @@ -232,13 +232,16 @@ def delete(request, document_id):
if not permission_policy.user_has_permission_for_instance(request.user, 'delete', doc):
raise PermissionDenied

next_url = get_valid_next_url_from_request(request)

if request.method == 'POST':
doc.delete()
messages.success(request, _("Document '{0}' deleted.").format(doc.title))
return redirect('wagtaildocs:index')
return redirect(next_url) if next_url else redirect('wagtaildocs:index')

return TemplateResponse(request, "wagtaildocs/documents/confirm_delete.html", {
'document': doc,
'next': next_url,
})


Expand Down
Expand Up @@ -20,6 +20,7 @@
<p>{% trans "Are you sure you want to delete this image?" %}</p>
<form action="{% url 'wagtailimages:delete' image.id %}" method="POST">
{% csrf_token %}
<input type="hidden" value="{{ next }}" name="next">
<input type="submit" value="{% trans 'Yes, delete' %}" class="button serious" />
<a href="{% url 'wagtailimages:index' %}" class="button button-secondary">{% trans "No, don't delete" %}</a>
</form>
Expand Down
4 changes: 2 additions & 2 deletions wagtail/images/templates/wagtailimages/images/edit.html
Expand Up @@ -55,7 +55,7 @@
<div class="u-hidden@xs">
<input type="submit" value="{% trans 'Save' %}" class="button" />
{% if user_can_delete %}
<a href="{% url 'wagtailimages:delete' image.id %}" class="button button-secondary no">{% trans "Delete image" %}</a>
<a href="{% url 'wagtailimages:delete' image.id %}{% if next %}?next={{ next }}{% endif %}" class="button button-secondary no">{% trans "Delete image" %}</a>
{% endif %}
</div>
</div>
Expand Down Expand Up @@ -112,7 +112,7 @@ <h2 class="label no-float u-text-transform-uppercase">{% trans "Focal point" %}
<div class="col5">
<input type="submit" value="{% trans 'Save' %}" class="button" />
{% if user_can_delete %}
<a href="{% url 'wagtailimages:delete' image.id %}" class="button button-secondary no">{% trans "Delete image" %}</a>
<a href="{% url 'wagtailimages:delete' image.id %}{% if next %}?next={{ next }}{% endif %}" class="button button-secondary no">{% trans "Delete image" %}</a>
{% endif %}
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion wagtail/images/views/images.py
Expand Up @@ -284,13 +284,16 @@ def delete(request, image_id):
if not permission_policy.user_has_permission_for_instance(request.user, 'delete', image):
raise PermissionDenied

next_url = get_valid_next_url_from_request(request)

if request.method == 'POST':
image.delete()
messages.success(request, _("Image '{0}' deleted.").format(image.title))
return redirect('wagtailimages:index')
return redirect(next_url) if next_url else redirect('wagtailimages:index')

return TemplateResponse(request, "wagtailimages/images/confirm_delete.html", {
'image': image,
'next': next_url,
})


Expand Down

0 comments on commit 1e14fe0

Please sign in to comment.