@require_POST
@login_required
def update_timeout(request, code):
    check = _get_rw_check_for_user(request, code)
    kind = request.POST.get('kind')
    if (kind == 'simple'):
        form = forms.TimeoutForm(request.POST)
        if (not form.is_valid()):
            return HttpResponseBadRequest()
        check.kind = 'simple'
        check.timeout = form.cleaned_data['timeout']
        check.grace = form.cleaned_data['grace']
    elif (kind == 'cron'):
        form = forms.CronForm(request.POST)
        if (not form.is_valid()):
            return HttpResponseBadRequest()
        check.kind = 'cron'
        check.schedule = form.cleaned_data['schedule']
        check.tz = form.cleaned_data['tz']
        check.grace = td(minutes=form.cleaned_data['grace'])
    check.alert_after = check.going_down_after()
    if ((check.status == 'up') and (check.alert_after < timezone.now())):
        check.alert_after = None
        check.status = 'down'
    check.save()
    if ('/details/' in request.META.get('HTTP_REFERER', '')):
        return redirect('hc-details', code)
    return redirect('hc-checks', check.project.code)
@require_POST
@login_required
def update_timeout(request, code):
    check = _get_rw_check_for_user(request, code)
    kind = request.POST.get('kind')
    if (kind == 'simple'):
        form = forms.TimeoutForm(request.POST)
        if (not form.is_valid()):
            return HttpResponseBadRequest()
        check.kind = 'simple'
        check.timeout = form.cleaned_data['timeout']
        check.grace = form.cleaned_data['grace']
    elif (kind == 'cron'):
        form = forms.CronForm(request.POST)
        if (not form.is_valid()):
            return HttpResponseBadRequest()
        check.kind = 'cron'
        check.schedule = form.cleaned_data['schedule']
        check.tz = form.cleaned_data['tz']
        check.grace = td(minutes=form.cleaned_data['grace'])
    check.alert_after = check.going_down_after()
    if ((check.status == 'up') and (check.alert_after < timezone.now())):
        check.alert_after = None
        check.status = 'down'
    check.save()
    if ('/details/' in request.META.get('HTTP_REFERER', )):
        return redirect('hc-details', code)
    return redirect('hc-checks', check.project.code)