Commit 207ebf6e authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

quotaholder: Change provisions argument to list

It is the API code's task to transform the input dict to list.
parent d404f588
......@@ -95,6 +95,21 @@ def get_pending_commissions(request):
return json_response(result)
def _provisions_to_list(provisions):
lst = []
for provision in provisions:
try:
holder = provision['holder']
source = provision['source']
resource = provision['resource']
quantity = provision['quantity']
key = (holder, source, resource)
lst.append((key, quantity))
except KeyError:
raise ValueError("Malformed provision")
return lst
@csrf_exempt
@api.api_method(http_method='POST', token_required=True, user_required=False)
@service_from_token
......@@ -104,6 +119,7 @@ def issue_commission(request):
client_key = str(request.service_instance)
provisions = input_data['provisions']
provisions = _provisions_to_list(provisions)
force = input_data.get('force', False)
auto_accept = input_data.get('auto_accept', False)
......
......@@ -84,21 +84,6 @@ def _get_holdings_for_update(holding_keys):
return holdings
def _provisions_to_list(provisions):
lst = []
for provision in provisions:
try:
holder = provision['holder']
source = provision['source']
resource = provision['resource']
quantity = provision['quantity']
key = (holder, source, resource)
lst.append((key, quantity))
except KeyError:
raise InvalidDataError("Malformed provision")
return lst
def _mkProvision(key, quantity):
holder, source, resource = key
return {'holder': holder,
......@@ -152,7 +137,6 @@ def issue_commission(context=None,
operations = Operations()
provisions_to_create = []
provisions = _provisions_to_list(provisions)
keys = [key for (key, value) in provisions]
holdings = _get_holdings_for_update(keys)
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment