def private_key_edit(request, pk): error = False privateKey = get_object_or_404(PrivateKey, pk=pk) if request.POST: if "cancel" in request.POST: return redirect('sparkle.views.index') form = PrivateKeyForm(request.POST, request.FILES, instance=privateKey) if form.is_valid(): form.save() return redirect('sparkle.views.index') else: form = PrivateKeyForm(instance=privateKey) context = {'form': form, 'privateKey': privateKey, 'error': error} return render_to_response( 'sparkle/forms/private_key.html', context, context_instance=RequestContext(request))
def private_key_add(request): error = False if request.POST: if "cancel" in request.POST: return redirect('sparkle.views.index') form = PrivateKeyForm(request.POST, request.FILES) if form.is_valid(): privateKey = form.save(commit=True) privateKey.save() return redirect('sparkle.views.index') else: error = True else: form = PrivateKeyForm() context = {'form': form, 'error': error} return render_to_response( 'sparkle/forms/private_key.html', context, context_instance=RequestContext(request))