Exemple #1
0
def tap_detail(request, tap_id):
    tap = get_object_or_404(models.KegTap, id=tap_id)
    available_kegs = models.Keg.objects.filter(online=False,
                                               finished=False).order_by('id')

    record_drink_form = forms.RecordDrinkForm()
    activate_keg_form = forms.ChangeKegForm()
    tap_settings_form = forms.TapForm(instance=tap)

    if request.method == 'POST':
        if 'submit_change_keg_form' in request.POST:
            activate_keg_form = forms.ChangeKegForm(request.POST)
            if activate_keg_form.is_valid():
                activate_keg_form.save(tap)
                messages.success(request,
                                 'The new keg was activated. Bottoms up!')
                return redirect('kegadmin-taps')

        if 'submit_keg_choice' in request.POST:
            keg_id = request.POST.get('keg_id')
            keg = models.Keg.objects.get(id=keg_id)
            d = request.backend.attach_keg(tap, keg)
            messages.success(request, 'The new keg was activated. Bottoms up!')
            return redirect('kegadmin-taps')

        elif 'submit_tap_form' in request.POST:
            tap_settings_form = forms.TapForm(request.POST, instance=tap)
            if tap_settings_form.is_valid():
                tap_settings_form.save()
                messages.success(request, 'Tap settings saved.')
                tap_settings_form = forms.TapForm(instance=tap)

        elif 'submit_delete_tap_form' in request.POST:
            delete_form = forms.DeleteTapForm(request.POST)
            if delete_form.is_valid():
                if tap.current_keg:
                    request.backend.end_keg(tap)
                tap.delete()
                messages.success(request, 'Tap deleted.')
                return redirect('kegadmin-taps')

        elif 'submit_end_keg_form' in request.POST:
            end_keg_form = forms.EndKegForm(request.POST)
            if end_keg_form.is_valid():
                old_keg = request.backend.end_keg(tap)
                messages.success(request, 'Keg %s was ended.' % old_keg.id)

        elif 'submit_record_drink' in request.POST:
            record_drink_form = forms.RecordDrinkForm(request.POST)
            if record_drink_form.is_valid():
                user = record_drink_form.cleaned_data.get('user')
                volume_ml = record_drink_form.cleaned_data.get('volume_ml')
                d = request.backend.record_drink(tap,
                                                 ticks=0,
                                                 username=user,
                                                 volume_ml=volume_ml)
                messages.success(request, 'Drink %s recorded.' % d.id)
            else:
                messages.error(request,
                               'Please enter a valid volume and user.')

        elif 'submit_record_spill' in request.POST:
            record_drink_form = forms.RecordDrinkForm(request.POST)
            if record_drink_form.is_valid():
                user = record_drink_form.cleaned_data.get('user')
                volume_ml = record_drink_form.cleaned_data.get('volume_ml')
                d = request.backend.record_drink(tap,
                                                 ticks=0,
                                                 username=user,
                                                 volume_ml=volume_ml,
                                                 spilled=True)
                messages.success(request, 'Spill recorded.')
            else:
                messages.error(request, 'Please enter a valid volume.')

        else:
            messages.warning(request, 'No form data was found. Bug?')

    end_keg_form = forms.EndKegForm(initial={'keg': tap.current_keg})

    context = RequestContext(request)
    context['tap'] = tap
    context['current_keg'] = tap.current_keg
    context['available_kegs'] = available_kegs
    context['activate_keg_form'] = activate_keg_form
    context['record_drink_form'] = record_drink_form
    context['end_keg_form'] = end_keg_form
    context['tap_settings_form'] = tap_settings_form
    context['delete_tap_form'] = forms.DeleteTapForm()
    return render_to_response('kegadmin/tap_detail.html',
                              context_instance=context)
Exemple #2
0
def tap_detail(request, tap_id):
    tap = get_object_or_404(models.KegTap, id=tap_id)
    available_kegs = models.Keg.objects.filter(
        status=models.Keg.STATUS_AVAILABLE).order_by("id")

    record_drink_form = forms.RecordDrinkForm()
    activate_keg_form = forms.ChangeKegForm()
    tap_settings_form = forms.TapForm(instance=tap)

    if request.method == "POST":
        if "submit_change_keg_form" in request.POST:
            activate_keg_form = forms.ChangeKegForm(request.POST)
            if activate_keg_form.is_valid():
                activate_keg_form.save(tap)
                messages.success(request,
                                 "The new keg was activated. Bottoms up!")
                return redirect("kegadmin-taps")

        if "submit_keg_choice" in request.POST:
            keg_id = request.POST.get("keg_id")
            keg = models.Keg.objects.get(id=keg_id)
            d = request.backend.attach_keg(tap, keg)
            messages.success(request, "The new keg was activated. Bottoms up!")
            return redirect("kegadmin-taps")

        elif "submit_tap_form" in request.POST:
            tap_settings_form = forms.TapForm(request.POST, instance=tap)
            if tap_settings_form.is_valid():
                tap_settings_form.save()
                messages.success(request, "Tap settings saved.")
                tap_settings_form = forms.TapForm(instance=tap)

        elif "submit_delete_tap_form" in request.POST:
            delete_form = forms.DeleteTapForm(request.POST)
            if delete_form.is_valid():
                if tap.current_keg:
                    request.backend.end_keg(tap.current_keg)
                tap.delete()
                messages.success(request, "Tap deleted.")
                return redirect("kegadmin-taps")

        elif "submit_end_keg_form" in request.POST:
            end_keg_form = forms.EndKegForm(request.POST)
            if end_keg_form.is_valid():
                old_keg = request.backend.end_keg(tap.current_keg)
                messages.success(request, "Keg %s was ended." % old_keg.id)

        elif "submit_record_drink" in request.POST:
            record_drink_form = forms.RecordDrinkForm(request.POST)
            if record_drink_form.is_valid():
                user = record_drink_form.cleaned_data.get("user")
                volume_ml = record_drink_form.cleaned_data.get("volume_ml")
                d = request.backend.record_drink(tap,
                                                 ticks=0,
                                                 username=user,
                                                 volume_ml=volume_ml)
                messages.success(request, "Drink %s recorded." % d.id)
            else:
                messages.error(request,
                               "Please enter a valid volume and user.")

        elif "submit_record_spill" in request.POST:
            record_drink_form = forms.RecordDrinkForm(request.POST)
            if record_drink_form.is_valid():
                user = record_drink_form.cleaned_data.get("user")
                volume_ml = record_drink_form.cleaned_data.get("volume_ml")
                d = request.backend.record_drink(tap,
                                                 ticks=0,
                                                 username=user,
                                                 volume_ml=volume_ml,
                                                 spilled=True)
                messages.success(request, "Spill recorded.")
            else:
                messages.error(request, "Please enter a valid volume.")

        else:
            messages.warning(request, "No form data was found. Bug?")

    end_keg_form = forms.EndKegForm(initial={"keg": tap.current_keg})

    context = {}
    context["tap"] = tap
    context["current_keg"] = tap.current_keg
    context["available_kegs"] = available_kegs
    context["activate_keg_form"] = activate_keg_form
    context["record_drink_form"] = record_drink_form
    context["end_keg_form"] = end_keg_form
    context["tap_settings_form"] = tap_settings_form
    context["delete_tap_form"] = forms.DeleteTapForm()
    return render(request, "kegadmin/tap_detail.html", context=context)