compute item amount from query string (#9174)

This commit is contained in:
Serghei Mihai 2015-12-22 14:19:17 +01:00
parent f497a9c8ad
commit 2a31f515cd
2 changed files with 6 additions and 2 deletions

7
README
View File

@ -25,7 +25,7 @@ API
Items amount can be added to basket through API by posting to
*/api/lingo/add-basket-item* endpoint a json payload containing *amount* and/or
*"extra": {"amount": ...}* attribute.
*"extra": {"amount": ...}* attribute or passing *amount* in the query string
For example:
@ -34,7 +34,10 @@ For example:
"amount": "42.42",
"extra": {"amount": "10.42", ...},
...
}
}
or
/api/lingo/add-basket-item?amount=10
The "amount" attribute should be float or decimal or a list of
floats/decimals. For example:

View File

@ -69,6 +69,7 @@ class AddBasketItemApiView(View):
extra = request_body.get('extra', {})
item = BasketItem(amount=0)
item.amount = sum([Decimal(x) for x in request.GET.getlist('amount')])
if request_body.get('amount'):
item.amount += self.get_amount(request_body['amount'])