Beispiel #1
0
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")),
            }))
Beispiel #2
0
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."),
    )
Beispiel #3
0
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."),
    )
Beispiel #4
0
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")),
    }))