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 = json.dumps({ "html": html, "message": _(u"Selected products have been removed from category.") }, cls=LazyEncoder) return HttpResponse(result, mimetype='application/json')
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 = json.dumps( { "html": html, "message": _(u"Selected products have been removed from category.") }, cls=LazyEncoder) return HttpResponse(result, content_type='application/json')
def add_products(request, category_id): """Adds products (passed via request body) to 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 try: category.products.add(product_id) except IntegrityError: continue product = Product.objects.get(pk=product_id) product_changed.send(product) 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 added to category.") }, cls=LazyEncoder) return HttpResponse(result)
def change_categories(request, product_id): """Changes categories by passed request body. """ product = lfs_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), mimetype="application/json" )
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"): continue product = Product.objects.get(pk=product_id) product_changed.send(product) category.products.remove(product_id) category_changed.send(category) inline = products_inline(request, category_id) return HttpResponse(inline)
def change_categories(request, product_id): """Changes categories by passed request body. """ product = lfs_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(json.dumps( { "message": _(u"Categories have been saved."), }, cls=LazyEncoder), content_type='application/json')