def new_cred_product(request, pid): prod = get_object_or_404(Product, pk=pid) if request.method == 'POST': tform = CredMappingFormProd(request.POST) if tform.is_valid(): # Select the credential mapping object from the selected list and only allow if the credential is associated with the product cred_user = Cred_Mapping.objects.filter( cred_id=tform.cleaned_data['cred_id'].id, product=pid).first() message = "Credential already associated." status_tag = 'alert-danger' if cred_user is None: prod = Product.objects.get(id=pid) new_f = tform.save(commit=False) new_f.product = prod new_f.save() message = 'Credential Successfully Updated.' status_tag = 'alert-success' messages.add_message( request, messages.SUCCESS, message, extra_tags=status_tag) return HttpResponseRedirect(reverse('all_cred_product', args=(pid, ))) else: tform = CredMappingFormProd() product_tab = Product_Tab(pid, title="Add Credential Configuration", tab="settings") return render(request, 'dojo/new_cred_product.html', { 'tform': tform, 'pid': pid, 'product_tab': product_tab })
def edit_cred_product(request, pid, ttid): cred = get_object_or_404(Cred_Mapping.objects.select_related('cred_id'), id=ttid) prod = get_object_or_404(Product, pk=pid) if request.method == 'POST': tform = CredMappingFormProd(request.POST, instance=cred) if tform.is_valid(): tform.save() messages.add_message(request, messages.SUCCESS, 'Credential Successfully Updated.', extra_tags='alert-success') return HttpResponseRedirect( reverse('all_cred_product', args=(pid, ))) else: tform = CredMappingFormProd(instance=cred) product_tab = Product_Tab(prod.id, title="Edit Product Credential", tab="settings") return render(request, 'dojo/edit_cred_all.html', { 'tform': tform, 'product_tab': product_tab, 'cred_type': "Product" })
def edit_cred_product(request, pid, ttid): cred = get_object_or_404( Cred_Mapping.objects.select_related('cred_id'), id=ttid) prod = get_object_or_404(Product, pk=pid) if request.method == 'POST': tform = CredMappingFormProd(request.POST, instance=cred) if tform.is_valid(): tform.save() messages.add_message( request, messages.SUCCESS, 'Credential Successfully Updated.', extra_tags='alert-success') return HttpResponseRedirect(reverse('all_cred_product', args=(pid, ))) else: tform = CredMappingFormProd(instance=cred) product_tab = Product_Tab(prod.id, title="Edit Product Credential", tab="settings") return render(request, 'dojo/edit_cred_all.html', { 'tform': tform, 'product_tab': product_tab, 'cred_type': "Product" })