Implement group delete functionality

This commit is contained in:
Nick Smith 2014-07-11 11:46:51 +01:00
parent 10a2984cde
commit 2543478dc3
4 changed files with 53 additions and 1 deletions

View file

@ -0,0 +1,33 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% block titletag %}{% trans "Delete group" %}{% endblock %}
{% block bodyclass %}menu-groups{% endblock %}
{% block content %}
{% trans "Delete group" as del_str %}
{% include "wagtailadmin/shared/header.html" with title=del_str subtitle=group.name icon="group" %}
<div class="row row-flush nice-padding">
<div class="col6">
<p>
{% blocktrans with group_user_count=group.user_set.count group_name=group.name %}The group '{{ group_name }}' has <strong>{{ group_user_count }}</strong> users assigned.{% endblocktrans %}
</p>
<p>
{% if group.user_set.count %}
If you delete the group, those users will lose the permissions
granted to them by membership of this group, but retain
permissions they have through membership of other groups.
{% else %}
It is probably safe to delete.
{% endif %}
</p>
</div>
<div class="col6">
<p>{% trans "Are you sure you want to delete this group?" %}</p>
<form action="{% url 'wagtailusers_groups_delete' group.id %}" method="POST">
{% csrf_token %}
<input type="submit" value="{% trans 'Yes, delete' %}" class="serious" />
</form>
</div>
</div>
{% endblock %}

View file

@ -16,7 +16,11 @@
{% include "wagtailadmin/shared/field_as_li.html" with field=form.name %}
{% format_permissions permission_bound_field=form.permissions %}
{% include "wagtailusers/groups/includes/page_permissions_formset.html" with formset=formset only %}
<li><input type="submit" value="{% trans 'Save' %}" /></li>
<li><input type="submit" value="{% trans 'Save' %}" />
{% if perms.auth.delete_group %}
<a href="{% url 'wagtailusers_groups_delete' group.id %}" class="button button-secondary no">{% trans "Delete group" %}</a>
{% endif %}
</li>
</ul>
</div>
</form>

View file

@ -5,4 +5,5 @@ urlpatterns = [
url(r'^$', groups.index, name='wagtailusers_groups_index'),
url(r'^new/$', groups.create, name='wagtailusers_groups_create'),
url(r'^(\d+)/$', groups.edit, name='wagtailusers_groups_edit'),
url(r'^(\d+)/delete/$', groups.delete, name='wagtailusers_groups_delete'),
]

View file

@ -133,3 +133,17 @@ def edit(request, group_id):
'form': form,
'formset': formset,
})
@permission_required('auth.delete_group')
def delete(request, group_id):
group = get_object_or_404(Group, id=group_id)
if request.POST:
group.delete()
messages.success(request, _("Group '{0}' deleted.").format(group.name))
return redirect('wagtailusers_groups_index')
return render(request, "wagtailusers/groups/confirm_delete.html", {
'group': group,
})