コード例 #1
0
def remove_products(request, group_id):
    """Remove products from given property group with given property_group_id.
    """
    property_group = lfs_get_object_or_404(PropertyGroup, pk=group_id)

    for temp_id in request.POST.keys():
        if temp_id.startswith("product"):
            temp_id = temp_id.split("-")[1]
            product = Product.objects.get(pk=temp_id)
            property_group.products.remove(product)

            # Notify removing
            product_removed_property_group.send(sender=property_group,
                                                product=product)

    html = [[
        "#products-inline",
        products_inline(request, group_id, as_string=True)
    ]]
    result = simplejson.dumps(
        {
            "html": html,
            "message": _(u"Products have been removed.")
        },
        cls=LazyEncoder)

    return HttpResponse(result, mimetype='application/json')
コード例 #2
0
ファイル: views.py プロジェクト: ranjithtenz/django-lfs
def remove_products(request, group_id):
    """Remove products from given property group with given property_group_id.
    """
    property_group = lfs_get_object_or_404(PropertyGroup, pk=group_id)

    for temp_id in request.POST.keys():
        if temp_id.startswith("product"):
            temp_id = temp_id.split("-")[1]
            product = Product.objects.get(pk=temp_id)
            property_group.products.remove(product)

            # Notify removing
            product_removed_property_group.send([property_group, product])

    html = [["#products-inline", products_inline(request, group_id, as_string=True)]]
    result = simplejson.dumps({"html": html, "message": _(u"Products have been removed.")}, cls=LazyEncoder)

    return HttpResponse(result)
コード例 #3
0
def update_property_groups(request, product_id):
    """Updates property groups for the product with passed id.
    """
    selected_group_ids = request.POST.getlist("selected-property-groups")

    for property_group in PropertyGroup.objects.all():
        # if the group is within selected groups we try to add it to the product
        # otherwise we try do delete it
        if str(property_group.id) in selected_group_ids:
            try:
                property_group.products.get(pk=product_id)
            except ObjectDoesNotExist:
                property_group.products.add(product_id)
        else:
            property_group.products.remove(product_id)
            product = Product.objects.get(pk=product_id)
            product_removed_property_group.send([property_group, product])

    url = reverse("lfs_manage_product", kwargs={"product_id": product_id})
    return HttpResponseRedirect(url)