Exemplo n.º 1
0
def group_delete(request, id, template_name="user_groups/delete.html"):
    group = get_object_or_404(Group, pk=id)

    if not has_perm(request.user, 'user_groups.delete_group', group):
        raise Http403

    if request.method == "POST":
        # send notification to administrators
        recipients = get_notice_recipients('module', 'groups',
                                           'grouprecipients')
        if recipients:
            if notification:
                extra_context = {
                    'object': group,
                    'request': request,
                }
                notification.send_emails(recipients, 'group_deleted',
                                         extra_context)

        EventLog.objects.log(instance=group)

        group.delete()
        return HttpResponseRedirect(reverse('group.search'))

    (deleted_objects, count, perms_needed,
     protected) = get_deleted_objects([group], request.user)
    object_name = group.label or group.name

    if perms_needed or protected:
        title = _("Cannot delete %(name)s") % {"name": object_name}
    else:
        title = _("Are you sure?")

    return render_to_resp(request=request,
                          template_name=template_name,
                          context={
                              'group': group,
                              "title": title,
                              "object_name": object_name,
                              "deleted_objects": deleted_objects,
                              "perms_lacking": perms_needed,
                              "protected": protected,
                              "opts": group._meta,
                          })
Exemplo n.º 2
0
def group_delete(request, id, template_name="user_groups/delete.html"):
    group = get_object_or_404(Group, pk=id)

    if not has_perm(request.user,'user_groups.delete_group',group): raise Http403

    if request.method == "POST":
        # send notification to administrators
        recipients = get_notice_recipients('module', 'groups', 'grouprecipients')
        if recipients:
            if notification:
                extra_context = {
                    'object': group,
                    'request': request,
                }
                notification.send_emails(recipients,'group_deleted', extra_context)

        EventLog.objects.log(instance=group)

        group.delete()
        return HttpResponseRedirect(reverse('group.search'))

    (deleted_objects, count, perms_needed, protected) = get_deleted_objects(
            [group], request.user)
    object_name = group.label or group.name

    if perms_needed or protected:
        title = _("Cannot delete %(name)s") % {"name": object_name}
    else:
        title = _("Are you sure?")

    return render_to_response(template_name,
            {'group':group,
             "title": title,
             "object_name": object_name,
             "deleted_objects": deleted_objects,
             "perms_lacking": perms_needed,
             "protected": protected,
             "opts": group._meta,
             },
        context_instance=RequestContext(request))