@require_setting('PD_VENDOR_KEY')
@login_required
def add_pdc_complete(request, code, state):
    if ('pd' not in request.session):
        return HttpResponseBadRequest()
    project = _get_rw_project_for_user(request, code)
    session_state = request.session.pop('pd')
    if (session_state != state):
        return HttpResponseBadRequest()
    if (request.GET.get('error') == 'cancelled'):
        messages.warning(request, 'PagerDuty setup was cancelled.')
        return redirect('hc-channels', project.code)
    channel = Channel(kind='pd', project=project)
    channel.value = json.dumps({'service_key': request.GET.get('service_key'), 'account': request.GET.get('account')})
    channel.save()
    channel.assign_all_checks()
    messages.success(request, 'The PagerDuty integration has been added!')
    return redirect('hc-channels', project.code)
@require_setting('PD_VENDOR_KEY')
@login_required
def add_pdc_complete(request, code, state):
    if ('pd' not in request.session):
        return HttpResponseBadRequest()
    project = _get_rw_project_for_user(request, code)
    session_state = request.session.pop('pd')
    if (session_state != state):
        return HttpResponseBadRequest()
    if (request.GET.get('error') == 'cancelled'):
        messages.warning(request, 'PagerDuty setup was cancelled.')
        return redirect('hc-channels', project.code)
    channel = Channel(kind='pd', project=project)
    channel.value = json.dumps({'service_key': request.GET.get('service_key'), 'account': request.GET.get('account')})
    channel.save()
    channel.assign_all_checks()
    messages.success(request, 'The PagerDuty integration has been added!')
    return redirect('hc-channels', project.code)