@user_passes_test((lambda u: u.is_staff))
def add_meta_data(request, eid):
    endpoint = Endpoint.objects.get(id=eid)
    if (request.method == 'POST'):
        form = DojoMetaDataForm(request.POST)
        if form.is_valid():
            (cf, created) = DojoMeta.objects.get_or_create(name=form.cleaned_data['name'], model_name='Endpoint', model_id=endpoint.id, value=form.cleaned_data['value'])
            cf.save()
            messages.add_message(request, messages.SUCCESS, 'Metadata added successfully.', extra_tags='alert-success')
            if ('add_another' in request.POST):
                return HttpResponseRedirect(reverse('add_meta_data', args=(eid,)))
            else:
                return HttpResponseRedirect(reverse('view_endpoint', args=(eid,)))
    else:
        form = DojoMetaDataForm(initial={'content_type': endpoint})
    add_breadcrumb(parent=endpoint, title='Add Metadata', top_level=False, request=request)
    product_tab = Product_Tab(endpoint.product.id, 'Add Metadata', tab='endpoints')
    return render(request, 'dojo/add_endpoint_meta_data.html', {'form': form, 'product_tab': product_tab, 'endpoint': endpoint})
@user_passes_test((lambda u: u.is_staff))
def add_meta_data(request, eid):
    endpoint = Endpoint.objects.get(id=eid)
    if (request.method == 'POST'):
        form = DojoMetaDataForm(request.POST)
        if form.is_valid():
            (cf, created) = DojoMeta.objects.get_or_create(name=form.cleaned_data['name'], model_name='Endpoint', model_id=endpoint.id, value=form.cleaned_data['value'])
            cf.save()
            messages.add_message(request, messages.SUCCESS, 'Metadata added successfully.', extra_tags='alert-success')
            if ('add_another' in request.POST):
                return HttpResponseRedirect(reverse('add_meta_data', args=(eid,)))
            else:
                return HttpResponseRedirect(reverse('view_endpoint', args=(eid,)))
    else:
        form = DojoMetaDataForm(initial={'content_type': endpoint})
    add_breadcrumb(parent=endpoint, title='Add Metadata', top_level=False, request=request)
    product_tab = Product_Tab(endpoint.product.id, 'Add Metadata', tab='endpoints')
    return render(request, 'dojo/add_endpoint_meta_data.html', {'form': form, 'product_tab': product_tab, 'endpoint': endpoint})