Example #1
0
def remove_products(request, category_id):
    """Removes product (passed via request body) from category with passed id.
    """
    category = Category.objects.get(pk=category_id)

    for product_id in request.POST.keys():

        if product_id.startswith("page") or product_id.startswith("filter") or \
           product_id.startswith("keep-session") or product_id.startswith("action"):
            continue

        product = Product.objects.get(pk=product_id)
        product_changed.send(product)

        category.products.remove(product_id)

    category_changed.send(category)

    html = [["#products-inline", products_inline(request, category_id, as_string=True)]]

    result = simplejson.dumps({
        "html": html,
        "message": _(u"Selected products have been removed from category.")
    }, cls=LazyEncoder)

    return HttpResponse(result)
Example #2
0
def remove_products(request, category_id):
    """Removes product (passed via request body) from category with passed id.
    """
    category = Category.objects.get(pk=category_id)

    for product_id in request.POST.keys():

        if product_id.startswith("page") or product_id.startswith("filter") or \
           product_id.startswith("keep-session") or product_id.startswith("action"):
            continue

        product = Product.objects.get(pk=product_id)
        product_changed.send(product)

        category.products.remove(product_id)

    category_changed.send(category)

    html = [[
        "#products-inline",
        products_inline(request, category_id, as_string=True)
    ]]

    result = simplejson.dumps(
        {
            "html": html,
            "message": _(u"Selected products have been removed from category.")
        },
        cls=LazyEncoder)

    return HttpResponse(result)
Example #3
0
def change_categories(request, product_id):
    """Changes categories by passed request body.
    """
    product = muecke_get_object_or_404(Product, pk=product_id)

    # Signal that the old categories of the product have been changed.
    for category in product.categories.all():
        category_changed.send(category)

    if request.method == "POST":
        product.categories = request.POST.getlist("categories")
        product.save()

    # Signal that the new categories of the product have been changed.
    for category in product.categories.all():
        category_changed.send(category)

    return HttpResponse(simplejson.dumps({
        "message": _(u"Categories have been saved."),
    }, cls=LazyEncoder))