def _tap_detail_post(request, tap): form = forms.DrinkPostForm(request.POST) if not form.is_valid(): raise kbapi.BadRequestError(_form_errors(form)) cd = form.cleaned_data if cd.get("pour_time") and cd.get("now"): pour_time = datetime.datetime.fromtimestamp(cd.get("pour_time")) pour_now = datetime.datetime.fromtimestamp(cd.get("now")) pour_time_ago = pour_now - pour_time pour_time = timezone.now() - pour_time_ago else: pour_time = None duration = cd.get("duration") if duration is None: duration = 0 try: drink = request.backend.record_drink( tap, ticks=cd["ticks"], volume_ml=cd.get("volume_ml"), username=cd.get("username"), pour_time=pour_time, duration=duration, shout=cd.get("shout"), tick_time_series=cd.get("tick_time_series"), photo=request.FILES.get("photo", None), ) return protolib.ToProto(drink, full=True) except backend.exceptions.BackendError as e: raise kbapi.ServerError(str(e))
def _tap_detail_post(request, tap): form = forms.DrinkPostForm(request.POST) if not form.is_valid(): raise kbapi.BadRequestError, _form_errors(form) cd = form.cleaned_data if cd.get('pour_time') and cd.get('now'): pour_time = datetime.datetime.fromtimestamp(cd.get('pour_time')) pour_now = datetime.datetime.fromtimestamp(cd.get('now')) pour_time_ago = pour_now - pour_time pour_time = timezone.now() - pour_time_ago else: pour_time = None duration = cd.get('duration') if duration is None: duration = 0 try: drink = request.backend.record_drink(tap, ticks=cd['ticks'], volume_ml=cd.get('volume_ml'), username=cd.get('username'), pour_time=pour_time, duration=duration, shout=cd.get('shout'), tick_time_series=cd.get('tick_time_series'), photo=request.FILES.get('photo', None)) return protolib.ToProto(drink, full=True) except backend.exceptions.BackendError, e: raise kbapi.ServerError(str(e))
def _tap_detail_post(request, tap): form = forms.DrinkPostForm(request.POST) if not form.is_valid(): raise kbapi.BadRequestError, _form_errors(form) cd = form.cleaned_data if cd.get('pour_time') and cd.get('now'): pour_time = datetime.datetime.fromtimestamp(cd.get('pour_time')) now = datetime.datetime.fromtimestamp(cd.get('now')) skew = datetime.datetime.now() - now pour_time += skew else: pour_time = None duration = cd.get('duration') if duration is None: duration = 0 b = KegbotBackend(site=request.kbsite) try: res = b.RecordDrink(tap_name=tap, ticks=cd['ticks'], volume_ml=cd.get('volume_ml'), username=cd.get('username'), pour_time=pour_time, duration=duration, auth_token=cd.get('auth_token'), spilled=cd.get('spilled'), shout=cd.get('shout')) return protolib.ToProto(res, full=True) except backend.BackendError, e: raise kbapi.ServerError(str(e))