manager: add choice between deleting the page, or also its subpages (#12754)
This commit is contained in:
parent
4fe99aea80
commit
78c1c2f5e4
|
@ -0,0 +1,27 @@
|
|||
{% extends "combo/manager_base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{{ view.model.get_verbose_name }}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<p>
|
||||
{% if display_choice %}
|
||||
{% blocktrans %}This page has subpages, what do you want to do with them?{% endblocktrans %}
|
||||
<ul class="choices">
|
||||
<li><label><input type="radio" name="choice" checked="checked" value="delete-one">{% trans 'Delete only this page' %}</label></li>
|
||||
<li><label><input type="radio" name="choice" value="delete-all">{% trans 'Delete this page and all subpages' %}</label></li>
|
||||
</ul>
|
||||
{% else %}
|
||||
{% blocktrans %}Are you sure you want to delete this page?{% endblocktrans %}
|
||||
{% endif %}
|
||||
</p>
|
||||
<div class="buttons">
|
||||
<button>{% trans 'Delete' %}</button>
|
||||
<a class="cancel" href="{{ object.get_absolute_url }}">{% trans 'Cancel' %}</a>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -210,7 +210,22 @@ page_view = requires_csrf_token(PageView.as_view())
|
|||
|
||||
class PageDeleteView(DeleteView):
|
||||
model = Page
|
||||
template_name = 'combo/generic_confirm_delete.html'
|
||||
template_name = 'combo/delete_page.html'
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
deleted_page = self.get_object()
|
||||
|
||||
if request.POST.get('choice') == 'delete-one':
|
||||
new_parent = deleted_page.parent_id
|
||||
Page.objects.filter(parent=deleted_page).update(parent=new_parent)
|
||||
|
||||
return self.delete(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
subpages = Page.objects.filter(parent=self.get_object().id)
|
||||
context = super(PageDeleteView, self).get_context_data()
|
||||
context['display_choice'] = True if subpages else False
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('combo-manager-homepage')
|
||||
|
|
|
@ -141,7 +141,44 @@ def test_delete_page(app, admin_user):
|
|||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
resp = resp.click('delete')
|
||||
assert 'Confirm Deletion' in resp.body
|
||||
assert '<button>Delete</button>' in resp.body
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://localhost:80/manage/'
|
||||
assert Page.objects.count() == 0
|
||||
|
||||
def test_delete_page_keep_child(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='One', slug='one', template_name='standard')
|
||||
page.save()
|
||||
page2 = Page(title='Two', slug='two', parent=page, template_name='standard')
|
||||
page2.save()
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
resp = resp.click('delete')
|
||||
assert '<button>Delete</button>' in resp.body
|
||||
assert 'Delete only this page' in resp.body
|
||||
assert 'Delete this page and all subpages' in resp.body
|
||||
|
||||
resp.form['choice'].value = 'delete-one'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://localhost:80/manage/'
|
||||
assert Page.objects.count() == 1
|
||||
assert Page.objects.get(id=page2.id) == page2
|
||||
|
||||
def test_delete_page_and_subpage(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='One', slug='one', template_name='standard')
|
||||
page.save()
|
||||
page2 = Page(title='Two', slug='two', parent=page, template_name='standard')
|
||||
page2.save()
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
resp = resp.click('delete')
|
||||
assert '<button>Delete</button>' in resp.body
|
||||
assert 'Delete only this page' in resp.body
|
||||
assert 'Delete this page and all subpages' in resp.body
|
||||
|
||||
resp.form['choice'].value = 'delete-all'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://localhost:80/manage/'
|
||||
assert Page.objects.count() == 0
|
||||
|
|
Loading…
Reference in New Issue