def AddNewFood(request): if len(request.POST) > 0: form = FoodForm(request.POST) if form.is_valid(): newFood = Food(**form.cleaned_data) newFood.save() return HttpResponseRedirect("/food") else: context = request.POST.dict() context["error"] = utils.GetFormSingleError(form) return RenderEditFoodPage(request, "addFood.html", context) else: return RenderEditFoodPage(request, "addFood.html")
def EditOrder(request, **kw): orderId = kw["orderId"] order = get_object_or_404(ClientOrder, id = orderId) if len(request.POST) > 0: form = ClientOrderForm(request.POST) if form.is_valid(): utils.SetModelFromDict(order, form.cleaned_data) order.save() return HttpResponseRedirect("/order/{}".format(orderId)) else: context = request.POST.dict() context["error"] = utils.GetFormSingleError(form) return render(request, "editOrder.html", context) else: context = dict(order.__dict__) return render(request, "editOrder.html", context)
def EditFood(request, **kw): foodId = kw["foodId"] food = get_object_or_404(Food, id=foodId) if len(request.POST) > 0: form = FoodForm(request.POST) if form.is_valid(): utils.SetModelFromDict(food, form.cleaned_data) food.save() return HttpResponseRedirect("/food") else: context = request.POST.dict() context["error"] = utils.GetFormSingleError(form) return RenderEditFoodPage(request, "editFood.html", context) else: context = dict(food.__dict__) context["measureid"] = str(context["measureid_id"]) return RenderEditFoodPage(request, "editFood.html", context)
def NewOrder(request, **kw): clientId = kw["clientId"] client = get_object_or_404(Client, id = clientId) if len(request.POST) > 0: form = ClientOrderForm(request.POST) if form.is_valid(): newOrder = ClientOrder(**form.cleaned_data) newOrder.clientid = client newOrder.date = datetime.datetime.now() newOrder.seen = False newOrder.save() return HttpResponseRedirect("/clients/{}".format(clientId)) else: context = request.POST.dict() context["error"] = utils.GetFormSingleError(form) return render(request, "addOrder.html", context) else: context = { "client": client } return render(request, "addOrder.html", context)
def AddOrderedFood(request, **kw): orderId = kw["orderId"] clOrder = get_object_or_404(ClientOrder, id = orderId) food = Food.objects.all().select_related("measureid").order_by("name") if len(request.POST) > 0: form = AddOrderedFoodForm(request.POST) if form.is_valid(): ordFood = OrderedFood(**form.cleaned_data) ordFood.orderid = clOrder ordFood.ready = False ordFood.save() return HttpResponseRedirect("/order/{}/addfood".format(orderId)) else: context = { "order": clOrder, "error": utils.GetFormSingleError(form) } else: context = { "order": clOrder } return utils.RenderWithPaging(request, "AddFoodToOrder.html", context, food, FOOD_PER_PAGE)