def METHOD_NAME(request, rule_id):
    """Controller for editing threshold rules"""
    rule = get_object_or_404(ThresholdRule, pk=rule_id)
    if request.method == 'POST':
        form = ThresholdForm(request.POST, instance=rule)
        metric = request.POST.get('target')
        if form.is_valid():
            handle_threshold_form(form, request)
            return redirect('threshold-index')
    else:
        form = ThresholdForm(instance=rule)
        metric = rule.target
    heading = 'Edit threshold rule'
    navpath = get_path() + [(heading,)]
    title = create_title(navpath)
    context = {
        'heading': heading,
        'form': form,
        'metric': metric,
        'title': title,
        'navpath': navpath,
        'id': rule.id,
    }
    return render(request, 'threshold/set_threshold.html', context)