def save_discount_data(request, id): """Saves discount data (via request body) to the discount with passed id. This is called via an AJAX request and returns JSON encoded data. """ discount = Discount.objects.get(pk=id) discount_form = DiscountForm(instance=discount, data=request.POST) if discount_form.is_valid(): discount_form.save() return lfs.core.utils.set_message_cookie( url=reverse("lfs_manage_discount", kwargs={"id": id}), msg=_(u"Discount data has been saved.") )
def save_discount_data(request, id): """Saves discount data (via request body) to the discount with passed id. This is called via an AJAX request and returns JSON encoded data. """ discount = Discount.objects.get(pk=id) discount_form = DiscountForm(instance=discount, data=request.POST) if discount_form.is_valid(): discount_form.save() return lfs.core.utils.set_message_cookie( url=reverse("lfs_manage_discount", kwargs={"id": id}), msg=_(u"Discount data has been saved."), )
def add_discount(request, template_name="manage/discounts/add_discount.html"): """Provides an add form and saves a new discount method. """ if request.method == "POST": form = DiscountForm(data=request.POST, files=request.FILES) if form.is_valid(): new_discount = form.save() return lfs.core.utils.set_message_cookie( url=reverse("lfs_manage_discount", kwargs={"id": new_discount.id}), msg=_(u"Discount method has been added."), ) else: form = DiscountForm() return render_to_response( template_name, RequestContext( request, { "navigation": navigation(request), "form": form, "came_from": request.REQUEST.get("came_from", reverse("lfs_manage_discounts")), }))
def add_discount(request, template_name="manage/discounts/add_discount.html"): """Provides an add form and saves a new discount method. """ if request.method == "POST": form = DiscountForm(data=request.POST, files=request.FILES) if form.is_valid(): new_discount = form.save() return lfs.core.utils.set_message_cookie( url=reverse("lfs_manage_discount", kwargs={"id": new_discount.id}), msg=_(u"Discount method has been added."), ) else: form = DiscountForm() return render_to_response( template_name, RequestContext( request, { "navigation": navigation(request), "form": form, "came_from": request.REQUEST.get("came_from", reverse("lfs_manage_discounts")), }, ), )