@user_passes_test((lambda u: u.is_staff))
def delete_endpoint(request, eid):
    endpoint = get_object_or_404(Endpoint, pk=eid)
    product = endpoint.product
    form = DeleteEndpointForm(instance=endpoint)
    from django.contrib.admin.utils import NestedObjects
    from django.db import DEFAULT_DB_ALIAS
    collector = NestedObjects(using=DEFAULT_DB_ALIAS)
    collector.collect([endpoint])
    rels = collector.nested()
    if (request.method == 'POST'):
        if (('id' in request.POST) and (str(endpoint.id) == request.POST['id'])):
            form = DeleteEndpointForm(request.POST, instance=endpoint)
            if form.is_valid():
                del endpoint.tags
                endpoint.delete()
                messages.add_message(request, messages.SUCCESS, 'Endpoint and relationships removed.', extra_tags='alert-success')
                return HttpResponseRedirect(reverse('view_endpoint', args=(product.id,)))
    product_tab = Product_Tab(endpoint.product.id, 'Delete Endpoint', tab='endpoints')
    return render(request, 'dojo/delete_endpoint.html', {'endpoint': endpoint, 'product_tab': product_tab, 'form': form, 'rels': rels})
@user_passes_test((lambda u: u.is_staff))
def delete_endpoint(request, eid):
    endpoint = get_object_or_404(Endpoint, pk=eid)
    product = endpoint.product
    form = DeleteEndpointForm(instance=endpoint)
    from django.contrib.admin.utils import NestedObjects
    from django.db import DEFAULT_DB_ALIAS
    collector = NestedObjects(using=DEFAULT_DB_ALIAS)
    collector.collect([endpoint])
    rels = collector.nested()
    if (request.method == 'POST'):
        if (('id' in request.POST) and (str(endpoint.id) == request.POST['id'])):
            form = DeleteEndpointForm(request.POST, instance=endpoint)
            if form.is_valid():
                del endpoint.tags
                endpoint.delete()
                messages.add_message(request, messages.SUCCESS, 'Endpoint and relationships removed.', extra_tags='alert-success')
                return HttpResponseRedirect(reverse('view_endpoint', args=(product.id,)))
    product_tab = Product_Tab(endpoint.product.id, 'Delete Endpoint', tab='endpoints')
    return render(request, 'dojo/delete_endpoint.html', {'endpoint': endpoint, 'product_tab': product_tab, 'form': form, 'rels': rels})