@require_setting('PUSHOVER_API_TOKEN')
@login_required
def add_pushover(request, code):
    project = _get_rw_project_for_user(request, code)
    if (request.method == 'POST'):
        state = token_urlsafe()
        failure_url = (settings.SITE_ROOT + reverse('hc-channels', args=[project.code]))
        success_url = (((settings.SITE_ROOT + reverse('hc-add-pushover', args=[project.code])) + '?') + urlencode({'state': state, 'prio': request.POST.get('po_priority', '0'), 'prio_up': request.POST.get('po_priority_up', '0')}))
        subscription_url = ((settings.PUSHOVER_SUBSCRIPTION_URL + '?') + urlencode({'success': success_url, 'failure': failure_url}))
        request.session['pushover'] = state
        return redirect(subscription_url)
    if ('pushover_user_key' in request.GET):
        if ('pushover' not in request.session):
            return HttpResponseForbidden()
        state = request.session.pop('pushover')
        if (request.GET.get('state') != state):
            return HttpResponseForbidden()
        if (request.GET.get('pushover_unsubscribed') == '1'):
            Channel.objects.filter(project=project, kind='po').delete()
            return redirect('hc-channels', project.code)
        form = forms.AddPushoverForm(request.GET)
        if (not form.is_valid()):
            return HttpResponseBadRequest()
        channel = Channel(project=project, kind='po')
        channel.value = form.get_value()
        channel.save()
        channel.assign_all_checks()
        messages.success(request, 'The Pushover integration has been added!')
        return redirect('hc-channels', project.code)
    ctx = {'page': 'channels', 'project': project, 'po_retry_delay': td(seconds=settings.PUSHOVER_EMERGENCY_RETRY_DELAY), 'po_expiration': td(seconds=settings.PUSHOVER_EMERGENCY_EXPIRATION)}
    return render(request, 'integrations/add_pushover.html', ctx)
@require_setting('PUSHOVER_API_TOKEN')
@login_required
def add_pushover(request, code):
    project = _get_rw_project_for_user(request, code)
    if (request.method == 'POST'):
        state = token_urlsafe()
        failure_url = (settings.SITE_ROOT + reverse('hc-channels', args=[project.code]))
        success_url = (((settings.SITE_ROOT + reverse('hc-add-pushover', args=[project.code])) + '?') + urlencode({'state': state, 'prio': request.POST.get('po_priority', '0'), 'prio_up': request.POST.get('po_priority_up', '0')}))
        subscription_url = ((settings.PUSHOVER_SUBSCRIPTION_URL + '?') + urlencode({'success': success_url, 'failure': failure_url}))
        request.session['pushover'] = state
        return redirect(subscription_url)
    if ('pushover_user_key' in request.GET):
        if ('pushover' not in request.session):
            return HttpResponseForbidden()
        state = request.session.pop('pushover')
        if (request.GET.get('state') != state):
            return HttpResponseForbidden()
        if (request.GET.get('pushover_unsubscribed') == '1'):
            Channel.objects.filter(project=project, kind='po').delete()
            return redirect('hc-channels', project.code)
        form = forms.AddPushoverForm(request.GET)
        if (not form.is_valid()):
            return HttpResponseBadRequest()
        channel = Channel(project=project, kind='po')
        channel.value = form.get_value()
        channel.save()
        channel.assign_all_checks()
        messages.success(request, 'The Pushover integration has been added!')
        return redirect('hc-channels', project.code)
    ctx = {'page': 'channels', 'project': project, 'po_retry_delay': td(seconds=settings.PUSHOVER_EMERGENCY_RETRY_DELAY), 'po_expiration': td(seconds=settings.PUSHOVER_EMERGENCY_EXPIRATION)}
    return render(request, 'integrations/add_pushover.html', ctx)