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 muecke.core.utils.set_message_cookie( url=reverse("muecke_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 muecke.core.utils.set_message_cookie( url=reverse("muecke_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("muecke_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 muecke.core.utils.set_message_cookie( url=reverse("muecke_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("muecke_manage_discounts")), }))
def discount_data(request, id, template_name="manage/discounts/data.html"): """Returns the discount data as html. This view is used as a part within the manage discount view. """ discount = Discount.objects.get(pk=id) return render_to_string( template_name, RequestContext(request, { "form": DiscountForm(instance=discount), "discount": discount, }))