Пример #1
0
def new_api_key(request):
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        form = forms.ApiKeyForm(request.POST)
        if form.is_valid():
            new_api_key = form.save()
            return redirect('display_api_key', key_id=new_api_key.id)
    else:
        form = forms.ApiKeyForm()
    c = {'form': form}
    return render(request, 'forms/new_api_key.html', c)
Пример #2
0
def edit_api_key(request, key_id):
    api_key = get_object_or_404(ApiKey, pk=int(key_id))
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':

        form = forms.ApiKeyForm(request.POST, instance=api_key)
        if form.is_valid():
            api_key = form.save()
            return redirect(api_keys)
    else:
        form = forms.ApiKeyForm(instance=api_key)
    c = {'form': form, 'api_key': api_key}
    return render(request, 'forms/edit_api_key.html', c)