def update_properties(request, product_id): """Updates properties for product with passed id. """ ppv_type = int(request.POST.get("type")) product = get_object_or_404(Product, pk=product_id) ProductPropertyValue.objects.filter(product=product_id, type=ppv_type).delete() # Update property values for key in request.POST.keys(): if not key.startswith("property"): continue property_id = key.split("-")[1] prop = get_object_or_404(Property, pk=property_id) for value in request.POST.getlist(key): if prop.is_valid_value(value): # we have to use get_or_create because it is possible that we get same property values twice, eg. # if we have a SELECT typ property assigned to two different groups, and both these groups bound # to the product. In this case we will have same property shown twice at management page ProductPropertyValue.objects.get_or_create(product=product, property=prop, value=value, type=ppv_type) update_product_cache(product) url = reverse("lfs_manage_product", kwargs={"product_id": product_id}) return HttpResponseRedirect(url)
def update_properties(request, product_id): """Updates properties for product with passed id. """ ppv_type = request.POST.get("type") product = get_object_or_404(Product, pk=product_id) ProductPropertyValue.objects.filter(product=product_id, type=ppv_type).delete() # Update property values for key in request.POST.keys(): if not key.startswith("property"): continue property_id = key.split("-")[1] prop = get_object_or_404(Property, pk=property_id) for value in request.POST.getlist(key): if prop.is_valid_value(value): ProductPropertyValue.objects.create(product=product, property=prop, value=value, type=ppv_type) update_product_cache(product) url = reverse("lfs_manage_product", kwargs={"product_id": product_id}) return HttpResponseRedirect(url)
def update_properties(request, product_id): """Updates properties for product with passed id. """ ppv_type = int(request.POST.get("type")) product = get_object_or_404(Product, pk=product_id) ProductPropertyValue.objects.filter(product=product_id, type=ppv_type).delete() # Update property values for key in request.POST.keys(): if not key.startswith("property"): continue _property, property_group_id, property_id = key.split("-") if property_group_id == '0': property_group_id = None prop = get_object_or_404(Property, pk=property_id) for value in request.POST.getlist(key): if prop.is_valid_value(value): # we have to use get_or_create because it is possible that we get same property values twice, eg. # if we have a SELECT typ property assigned to two different groups, and both these groups bound # to the product. In this case we will have same property shown twice at management page ProductPropertyValue.objects.get_or_create( product=product, property_group_id=property_group_id, property=prop, value=value, type=ppv_type) update_product_cache(product) url = reverse("lfs_manage_product", kwargs={"product_id": product_id}) return HttpResponseRedirect(url)
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") product = Product.objects.get(pk=product_id) 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_removed_property_group.send(send=property_group, product=product) update_product_cache(product) url = reverse("lfs_manage_product", kwargs={"product_id": product_id}) return HttpResponseRedirect(url)
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") product = Product.objects.get(pk=product_id) 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_removed_property_group.send([property_group, product]) update_product_cache(product) url = reverse("lfs_manage_product", kwargs={"product_id": product_id}) return HttpResponseRedirect(url)