def tap_calibrate(request, tap_id): # TODO(mikey): This would make more semantic sense as PATCH /taps/tap-name/, # but Django's support for non-POST verbs is poor (specifically wrt request # body/form handling). tap = get_object_or_404(models.KegTap, meter_name=tap_id) form = forms.CalibrateTapForm(request.POST) if form.is_valid(): tap.ml_per_tick = form.cleaned_data['ml_per_tick'] tap.save() else: raise kbapi.BadRequestError, _form_errors(form) return protolib.ToProto(tap, full=True)
def tap_calibrate(request, meter_name_or_id): # TODO(mikey): This would make more semantic sense as PATCH /taps/tap-name/, # but Django's support for non-POST verbs is poor (specifically wrt request # body/form handling). tap = get_tap_from_meter_name_or_404(meter_name_or_id) meter = tap.current_meter() if not meter: raise kbapi.BadRequestError('Tap does not have a meter!') form = forms.CalibrateTapForm(request.POST) if form.is_valid(): meter.ticks_per_ml = 1.0 / form.cleaned_data['ml_per_tick'] meter.save() tap = get_tap_from_meter_name_or_404(meter_name_or_id) else: raise kbapi.BadRequestError, _form_errors(form) return protolib.ToProto(tap, full=True)