@login_required
def edit_webhook(request, code):
    channel = _get_rw_channel_for_user(request, code)
    if (channel.kind != 'webhook'):
        return HttpResponseBadRequest()
    if (request.method == 'POST'):
        form = forms.WebhookForm(request.POST)
        if form.is_valid():
            channel.name = form.cleaned_data['name']
            channel.value = form.get_value()
            channel.save()
            return redirect('hc-channels', channel.project.code)
    else:

        def flatten(d):
            return '\n'.join((('%s: %s' % pair) for pair in d.items()))
        doc = json.loads(channel.value)
        doc['headers_down'] = flatten(doc['headers_down'])
        doc['headers_up'] = flatten(doc['headers_up'])
        doc['name'] = channel.name
        form = forms.WebhookForm(doc)
    ctx = {'page': 'channels', 'project': channel.project, 'channel': channel, 'form': form}
    return render(request, 'integrations/webhook_form.html', ctx)
@login_required
def edit_webhook(request, code):
    channel = _get_rw_channel_for_user(request, code)
    if (channel.kind != 'webhook'):
        return HttpResponseBadRequest()
    if (request.method == 'POST'):
        form = forms.WebhookForm(request.POST)
        if form.is_valid():
            channel.name = form.cleaned_data['name']
            channel.value = form.get_value()
            channel.save()
            return redirect('hc-channels', channel.project.code)
    else:

        def flatten(d):
            return '\n'.join((('%s: %s' % pair) for pair in d.items()))
        doc = json.loads(channel.value)
        doc['headers_down'] = flatten(doc['headers_down'])
        doc['headers_up'] = flatten(doc['headers_up'])
        doc['name'] = channel.name
        form = forms.WebhookForm(doc)
    ctx = {'page': 'channels', 'project': channel.project, 'channel': channel, 'form': form}
    return render(request, 'integrations/webhook_form.html', ctx)