def add_products(request, manufacturer_id): """Adds products (passed via request body) to category with passed id. """ manufacturer = Manufacturer.objects.get(pk=manufacturer_id) for product_id in request.POST.keys(): if product_id.startswith("manufacturer_page") or product_id.startswith("manufacturer_filter") or \ product_id.startswith("keep-session") or product_id.startswith("action"): continue try: product = Product.objects.get(pk=product_id) product.manufacturer = manufacturer product.save() product_changed.send(product) except Product.DoesNotExist: continue manufacturer_changed.send(manufacturer) html = [["#products-inline", products_inline(request, manufacturer_id, as_string=True)]] result = json.dumps({ "html": html, "message": _(u"Selected products have been assigned to manufacturer.") }, cls=LazyEncoder) return HttpResponse(result, content_type='application/json')
def add_products(request, manufacturer_id): """Adds products (passed via request body) to category with passed id. """ manufacturer = Manufacturer.objects.get(pk=manufacturer_id) for product_id in request.POST.keys(): if product_id.startswith("manufacturer_page") or product_id.startswith("manufacturer_filter") or \ product_id.startswith("keep-session") or product_id.startswith("action"): continue try: product = Product.objects.get(pk=product_id) product.manufacturer = manufacturer product.save() product_changed.send(product) except Product.DoesNotExist: continue manufacturer_changed.send(manufacturer) html = [[ "#products-inline", products_inline(request, manufacturer_id, as_string=True) ]] result = json.dumps( { "html": html, "message": _(u"Selected products have been assigned to manufacturer.") }, cls=LazyEncoder) return HttpResponse(result, content_type='application/json')
def remove_products(request, manufacturer_id): """Removes product (passed via request body) from category with passed id. """ manufacturer = Manufacturer.objects.get(pk=manufacturer_id) for product_id in request.POST.keys(): if product_id.startswith("manufacturer_page") or product_id.startswith("manufacturer_filter") or \ product_id.startswith("keep-session") or product_id.startswith("action"): continue product = Product.objects.get(pk=product_id) product.manufacturer = None product.save() product_changed.send(product) manufacturer_changed.send(manufacturer) html = [[ "#products-inline", products_inline(request, manufacturer_id, as_string=True) ]] result = json.dumps( { "html": html, "message": _(u"Selected products are no longer assigned to manufacturer.") }, cls=LazyEncoder) return HttpResponse(result, content_type='application/json')
def remove_products(request, manufacturer_id): """Removes product (passed via request body) from category with passed id. """ manufacturer = Manufacturer.objects.get(pk=manufacturer_id) for product_id in request.POST.keys(): if ( product_id.startswith("manufacturer_page") or product_id.startswith("manufacturer_filter") or product_id.startswith("keep-session") or product_id.startswith("action") ): continue product = Product.objects.get(pk=product_id) product.manufacturer = None product.save() product_changed.send(product) manufacturer_changed.send(manufacturer) html = [["#products-inline", products_inline(request, manufacturer_id, as_string=True)]] result = simplejson.dumps( {"html": html, "message": _(u"Selected products are no longer assigned to manufacturer.")}, cls=LazyEncoder ) return HttpResponse(result, mimetype="application/json")