def keg_detail(request, keg_id): keg = get_object_or_404(models.Keg, id=keg_id) edit_form = forms.EditKegForm(instance=keg) if request.method == "POST": if "submit_edit_keg" in request.POST: edit_form = forms.EditKegForm(request.POST, instance=keg) if edit_form.is_valid(): edit_form.save() messages.success(request, "Keg updated.") return redirect("kegadmin-kegs") elif "submit_delete_keg" in request.POST: request.backend.cancel_keg(keg) messages.success(request, "Keg deleted.") return redirect("kegadmin-kegs") elif "submit_reactivate" in request.POST: request.backend.reactivate_keg(keg) messages.success(request, "Keg reactivated.") return redirect("kegadmin-edit-keg", keg_id=keg.id) elif "submit_end" in request.POST: request.backend.end_keg(keg) messages.success(request, "Keg ended.") return redirect("kegadmin-edit-keg", keg_id=keg.id) context = {} context["keg"] = keg context["remaining"] = keg.remaining_volume_ml() context["edit_form"] = edit_form return render(request, "kegadmin/keg_detail.html", context=context)
def keg_detail(request, keg_id): keg = get_object_or_404(models.Keg, id=keg_id) edit_form = forms.EditKegForm(instance=keg) if request.method == 'POST': if 'submit_edit_keg' in request.POST: edit_form = forms.EditKegForm(request.POST, instance=keg) if edit_form.is_valid(): edit_form.save() messages.success(request, 'Keg updated.') return redirect('kegadmin-kegs') elif 'submit_delete_keg' in request.POST: request.backend.cancel_keg(keg) messages.success(request, 'Keg deleted.') return redirect('kegadmin-kegs') elif 'submit_reactivate' in request.POST: request.backend.reactivate_keg(keg) messages.success(request, 'Keg reactivated.') return redirect('kegadmin-edit-keg', keg_id=keg.id) elif 'submit_end' in request.POST: request.backend.end_keg(keg) messages.success(request, 'Keg ended.') return redirect('kegadmin-edit-keg', keg_id=keg.id) context = {} context['keg'] = keg context['remaining'] = keg.remaining_volume_ml() context['edit_form'] = edit_form return render(request, 'kegadmin/keg_detail.html', context=context)
def keg_detail(request, keg_id): keg = get_object_or_404(models.Keg, id=keg_id) form = forms.EditKegForm(instance=keg) if request.method == 'POST': form = forms.EditKegForm(request.POST, instance=keg) if form.is_valid(): form.save() messages.success(request, 'Keg updated.') return redirect('kegadmin-kegs') context = RequestContext(request) context['keg'] = keg context['remaining'] = keg.remaining_volume_ml() context['form'] = form return render_to_response('kegadmin/keg_detail.html', context_instance=context)