@login_required
def channels(request, code):
    (project, rw) = _get_project_for_user(request, code)
    if (request.method == 'POST'):
        if (not rw):
            return HttpResponseForbidden()
        code = request.POST['channel']
        try:
            channel = Channel.objects.get(code=code)
        except Channel.DoesNotExist:
            return HttpResponseBadRequest()
        if (channel.project_id != project.id):
            return HttpResponseForbidden()
        new_checks = []
        for key in request.POST:
            if key.startswith('check-'):
                code = key[6:]
                try:
                    check = Check.objects.get(code=code)
                except Check.DoesNotExist:
                    return HttpResponseBadRequest()
                if (check.project_id != project.id):
                    return HttpResponseForbidden()
                new_checks.append(check)
        channel.checks.set(new_checks)
        return redirect('hc-channels', project.code)
    channels = Channel.objects.filter(project=project)
    channels = channels.order_by('created')
    channels = channels.annotate(n_checks=Count('checks'))
    ctx = {'page': 'channels', 'rw': rw, 'project': project, 'profile': project.owner_profile, 'channels': channels, 'enable_apprise': (settings.APPRISE_ENABLED is True), 'enable_call': (settings.TWILIO_AUTH is not None), 'enable_discord': (settings.DISCORD_CLIENT_ID is not None), 'enable_linenotify': (settings.LINENOTIFY_CLIENT_ID is not None), 'enable_matrix': (settings.MATRIX_ACCESS_TOKEN is not None), 'enable_pdc': (settings.PD_VENDOR_KEY is not None), 'enable_pushbullet': (settings.PUSHBULLET_CLIENT_ID is not None), 'enable_pushover': (settings.PUSHOVER_API_TOKEN is not None), 'enable_shell': (settings.SHELL_ENABLED is True), 'enable_slack_btn': (settings.SLACK_CLIENT_ID is not None), 'enable_sms': (settings.TWILIO_AUTH is not None), 'enable_telegram': (settings.TELEGRAM_TOKEN is not None), 'enable_trello': (settings.TRELLO_APP_KEY is not None), 'enable_whatsapp': settings.TWILIO_USE_WHATSAPP, 'use_payments': settings.USE_PAYMENTS}
    return render(request, 'front/channels.html', ctx)
@login_required
def channels(request, code):
    (project, rw) = _get_project_for_user(request, code)
    if (request.method == 'POST'):
        if (not rw):
            return HttpResponseForbidden()
        code = request.POST['channel']
        try:
            channel = Channel.objects.get(code=code)
        except Channel.DoesNotExist:
            return HttpResponseBadRequest()
        if (channel.project_id != project.id):
            return HttpResponseForbidden()
        new_checks = []
        for key in request.POST:
            if key.startswith('check-'):
                code = key[6:]
                try:
                    check = Check.objects.get(code=code)
                except Check.DoesNotExist:
                    return HttpResponseBadRequest()
                if (check.project_id != project.id):
                    return HttpResponseForbidden()
                new_checks.append(check)
        channel.checks.set(new_checks)
        return redirect('hc-channels', project.code)
    channels = Channel.objects.filter(project=project)
    channels = channels.order_by('created')
    channels = channels.annotate(n_checks=Count('checks'))
    ctx = {'page': 'channels', 'rw': rw, 'project': project, 'profile': project.owner_profile, 'channels': channels, 'enable_apprise': (settings.APPRISE_ENABLED is True), 'enable_call': (settings.TWILIO_AUTH is not None), 'enable_discord': (settings.DISCORD_CLIENT_ID is not None), 'enable_linenotify': (settings.LINENOTIFY_CLIENT_ID is not None), 'enable_matrix': (settings.MATRIX_ACCESS_TOKEN is not None), 'enable_pdc': (settings.PD_VENDOR_KEY is not None), 'enable_pushbullet': (settings.PUSHBULLET_CLIENT_ID is not None), 'enable_pushover': (settings.PUSHOVER_API_TOKEN is not None), 'enable_shell': (settings.SHELL_ENABLED is True), 'enable_slack_btn': (settings.SLACK_CLIENT_ID is not None), 'enable_sms': (settings.TWILIO_AUTH is not None), 'enable_telegram': (settings.TELEGRAM_TOKEN is not None), 'enable_trello': (settings.TRELLO_APP_KEY is not None), 'enable_whatsapp': settings.TWILIO_USE_WHATSAPP, 'use_payments': settings.USE_PAYMENTS}
    return render(request, 'front/channels.html', ctx)