Beispiel #1
0
def save_data(request, id):
    """
    Saves the data for the customer tax with given id.
    """
    customer_tax = get_object_or_404(CustomerTax, pk=id)
    form = CustomerTaxForm(instance=customer_tax,
                           data=request.POST,
                           files=request.FILES)
    if form.is_valid():
        form.save()
        form = None

    html = [
        ["#data", data(request, customer_tax, form=form)],
        ["#navigation", navigation(request, customer_tax)],
    ]

    result = json.dumps(
        {
            "html": html,
            "message": _(u"Data have been saved."),
        },
        cls=LazyEncoder)

    return HttpResponse(result, content_type='application/json')
Beispiel #2
0
def add_customer_tax(request,
                     template_name="manage/customer_tax/add_customer_tax.html"
                     ):
    """Provides a form to add a new customer tax.
    """
    if request.method == "POST":
        form = CustomerTaxForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            tax = form.save()

            return lfs.core.utils.set_message_cookie(
                url=reverse("lfs_manage_customer_tax", kwargs={"id": tax.id}),
                msg=_(u"Customer tax has been added."),
            )
    else:
        form = CustomerTaxForm()

    return render(
        request, template_name, {
            "form":
            form,
            "customer_taxes":
            CustomerTax.objects.all(),
            "next":
            (request.POST if request.method == 'POST' else request.GET).get(
                "next", request.META.get("HTTP_REFERER")),
        })
Beispiel #3
0
def manage_customer_tax(request,
                        id,
                        template_name="manage/customer_tax/customer_tax.html"):
    """Displays the main form to manage customer taxes.
    """
    customer_tax = get_object_or_404(CustomerTax, pk=id)
    if request.method == "POST":
        form = CustomerTaxForm(instance=customer_tax,
                               data=request.POST,
                               files=request.FILES)
        if form.is_valid():
            form.save()
            return lfs.core.utils.set_message_cookie(
                url=reverse("lfs_manage_customer_tax",
                            kwargs={"id": customer_tax.id}),
                msg=_(u"Customer tax has been saved."),
            )
    else:
        form = CustomerTaxForm(instance=customer_tax)

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                "customer_tax": customer_tax,
                "customer_taxes": CustomerTax.objects.all(),
                "form": form,
                "current_id": int(id),
            }))
Beispiel #4
0
def add_customer_tax(request, template_name="manage/customer_tax/add_customer_tax.html"):
    """Provides a form to add a new customer tax.
    """
    if request.method == "POST":
        form = CustomerTaxForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            tax = form.save()

            return lfs.core.utils.set_message_cookie(
                url=reverse("lfs_manage_customer_tax", kwargs={"id": tax.id}),
                msg=_(u"Customer tax has been added."),
            )
    else:
        form = CustomerTaxForm()

    return render_to_response(template_name, RequestContext(request, {
        "form": form,
        "customer_taxes": CustomerTax.objects.all(),
        "next": request.REQUEST.get("next", request.META.get("HTTP_REFERER")),
    }))
Beispiel #5
0
def manage_customer_tax(request, id, template_name="manage/customer_tax/customer_tax.html"):
    """Displays the main form to manage customer taxes.
    """
    customer_tax = get_object_or_404(CustomerTax, pk=id)
    if request.method == "POST":
        form = CustomerTaxForm(instance=customer_tax, data=request.POST, files=request.FILES)
        if form.is_valid():
            form.save()
            return lfs.core.utils.set_message_cookie(
                url=reverse("lfs_manage_customer_tax", kwargs={"id": customer_tax.id}),
                msg=_(u"Customer tax has been saved."),
            )
    else:
        form = CustomerTaxForm(instance=customer_tax)

    return render_to_response(template_name, RequestContext(request, {
        "customer_tax": customer_tax,
        "customer_taxes": CustomerTax.objects.all(),
        "form": form,
        "current_id": int(id),
    }))
Beispiel #6
0
def save_data(request, id):
    """
    Saves the data for the customer tax with given id.
    """
    customer_tax = get_object_or_404(CustomerTax, pk=id)
    form = CustomerTaxForm(instance=customer_tax, data=request.POST, files=request.FILES)
    if form.is_valid():
        form.save()
        form = None

    html = [
        ["#data", data(request, customer_tax, form=form)],
        ["#navigation", navigation(request, customer_tax)],
    ]

    result = json.dumps({
        "html": html,
        "message": _(u"Data have been saved."),
    }, cls=LazyEncoder)

    return HttpResponse(result, mimetype='application/json')