@user_passes_test((lambda u: u.is_staff))
def edit_meta_data(request, eid):
    endpoint = Endpoint.objects.get(id=eid)
    endpoint_cf = endpoint.endpoint_meta.all()
    endpoint_metadata = {}
    for cf in endpoint_cf:
        cfv = cf.value
        if len(cfv):
            endpoint_metadata[cf] = cfv
    if (request.method == 'POST'):
        for (key, value) in request.POST.iteritems():
            if key.startswith('cfv_'):
                cfv_id = int(key.split('_')[1])
                cfv = get_object_or_404(CustomFieldValue, id=cfv_id)
                value = value.strip()
                if value:
                    cfv.value = value
                    cfv.save()
                else:
                    cfv.delete()
        messages.add_message(request, messages.SUCCESS, 'Metadata edited successfully.', extra_tags='alert-success')
        return HttpResponseRedirect(reverse('view_endpoint', args=(eid,)))
    product_tab = Product_Tab(endpoint.product.id, 'Edit Metadata', tab='endpoints')
    return render(request, 'dojo/edit_endpoint_meta_data.html', {'endpoint': endpoint, 'product_tab': product_tab, 'endpoint_metadata': endpoint_metadata})
@user_passes_test((lambda u: u.is_staff))
def edit_meta_data(request, eid):
    endpoint = Endpoint.objects.get(id=eid)
    endpoint_cf = endpoint.endpoint_meta.all()
    endpoint_metadata = {}
    for cf in endpoint_cf:
        cfv = cf.value
        if len(cfv):
            endpoint_metadata[cf] = cfv
    if (request.method == 'POST'):
        for (key, value) in request.POST.iteritems():
            if key.startswith('cfv_'):
                cfv_id = int(key.split('_')[1])
                cfv = get_object_or_404(CustomFieldValue, id=cfv_id)
                value = value.strip()
                if value:
                    cfv.value = value
                    cfv.save()
                else:
                    cfv.delete()
        messages.add_message(request, messages.SUCCESS, 'Metadata edited successfully.', extra_tags='alert-success')
        return HttpResponseRedirect(reverse('view_endpoint', args=(eid,)))
    product_tab = Product_Tab(endpoint.product.id, 'Edit Metadata', tab='endpoints')
    return render(request, 'dojo/edit_endpoint_meta_data.html', {'endpoint': endpoint, 'product_tab': product_tab, 'endpoint_metadata': endpoint_metadata})