@permission_required("core.manage_shop")
@require_POST
def add_option(request, property_id):
    """Adds option to property with passed property id.
    """
    property = get_object_or_404(Property, pk=property_id)

    if request.POST.get("action") == "add":
        name = request.POST.get("name", "")
        price = request.POST.get("price", "")
        try:
            price = float(price)
        except ValueError:
            price = 0.0

        if name != "":
            option = PropertyOption.objects.create(name=name, price=price, property_id=property_id)
            message = _(u"Option has been added.")
        else:
            message = _(u"Option could not be added.")
    else:

        for option_id in request.POST.getlist("option"):

            try:
                option = PropertyOption.objects.get(pk=option_id)
            except PropertyOption.DoesNotExist:
                pass
            else:
                try:
                    price = float(request.POST.get("price-%s" % option_id, ""))
                except ValueError:
                    price = 0.0

                try:
                    position = int(request.POST.get("position-%s" % option_id, 99))
                except ValueError:
                    position = 99

                option.position = position
                option.name = request.POST.get(option_id % "name-%s", "")
                option.price = price
                option.save()
        message = _(u"Options have been updated.")

    _update_positions(property)
    # invalidate global properties version number (all product property caches will be invalidated)
    invalidate_cache_group_id('global-properties-version')

    html = [["#options", options_inline(request, property_id)]]
    result = json.dumps({
        "html": html,
        "message": message
    }, cls=LazyEncoder)
    return HttpResponse(result, content_type='application/json')
dataset/ETHPy150Open diefenbach/django-lfs/lfs/manage/property/views.py/add_option/swapped operands of `%`