Fixed bug in bulkBuy when not buying deposit

This commit is contained in:
seba 2011-10-18 02:56:29 +02:00
parent 16a0686b03
commit 939159a1c9
1 changed files with 18 additions and 15 deletions

View File

@ -132,18 +132,21 @@ class BuyableItemHandler(BaseHandler):
ret = rc.BAD_REQUEST ret = rc.BAD_REQUEST
ret.write("\nYou need to specify either items or deposits (or both).\n") ret.write("\nYou need to specify either items or deposits (or both).\n")
return ret return ret
if not request.data.has_key("items"):
request.data['items'] = []
if not request.data.has_key("deposits"):
request.data['deposits'] = []
itemList = [] itemList = []
try: try:
if not isinstance(request.data['items'], Iterable):
raise TypeError()
itemList += request.data['items']
if request.data.has_key('items'): if request.data.has_key('items'):
if not isinstance(request.data['items'], Iterable): if not isinstance(request.data['deposits'], Iterable):
raise TypeError() raise TypeError()
itemList += request.data['items'] itemList += request.data['deposits']
if request.data.has_key('deposits'):
if request.data.has_key('items'):
if not isinstance(request.data['deposits'], Iterable):
raise TypeError()
itemList += request.data['deposits']
except TypeError: except TypeError:
ret = rc.BAD_REQUEST ret = rc.BAD_REQUEST
ret.write("\nThe items/deposists parameter have to be a list.\n") ret.write("\nThe items/deposists parameter have to be a list.\n")
@ -182,14 +185,14 @@ class BuyableItemHandler(BaseHandler):
order.create(request.user) order.create(request.user)
order.save() order.save()
purchases = [] purchases = []
if request.data.has_key('items'): # buy items
for item in request.data['items']: for item in request.data['items']:
p = Purchase.create(order, ids[item], isDeposit=False) p = Purchase.create(order, ids[item], isDeposit=False)
p.save() p.save()
if request.data.has_key('deposits'): # buy deposits
for item in request.data['deposits']: for item in request.data['deposits']:
p = Purchase.create(order, ids[item], isDeposit=True) p = Purchase.create(order, ids[item], isDeposit=True)
p.save() p.save()
order.updatePrice(commit=True) order.updatePrice(commit=True)
order.save() order.save()