@permission_required("core.manage_shop")
def update_shipping_prices(request, shipping_method_id):
    """Saves/Deletes shipping prices with passed ids (via request body)
    dependent on given action (via request body).
    """
    shipping_method = get_object_or_404(ShippingMethod, pk=shipping_method_id)

    action = request.POST.get("action")
    if action == "delete":
        message = _(u"Prices have been deleted")
        for key in request.POST.keys():
            if key.startswith("delete-"):
                try:
                    id = key.split("-")[1]
                    price = get_object_or_404(ShippingMethodPrice, pk=id)
                except (IndexError, __HOLE__):
                    continue
                else:
                    price.delete()

    elif action == "update":
        message = _(u"Prices have been updated")
        for key, value in request.POST.items():
            if key.startswith("price-"):
                try:
                    id = key.split("-")[1]
                    price = get_object_or_404(ShippingMethodPrice, pk=id)
                except (IndexError, ObjectDoesNotExist):
                    continue
                else:
                    try:
                        value = float(value)
                    except ValueError:
                        value = 0.0
                    price.price = value
                    price.priority = request.POST.get("priority-%s" % id, 0)
                    price.save()

    _update_price_positions(shipping_method)

    html = [["#prices", shipping_method_prices(request, shipping_method_id)]]
    result = json.dumps({
        "html": html,
        "message": message,
    }, cls=LazyEncoder)

    return HttpResponse(result, content_type='application/json')
dataset/ETHPy150Open diefenbach/django-lfs/lfs/manage/shipping_methods/views.py/update_shipping_prices