Browse Source

Code cosmetics

master
Niklas Brachmann 11 years ago
parent
commit
19be70d545
  1. 29
      cash/api.py

29
cash/api.py

@ -30,7 +30,8 @@ ERR_AUTH_KEY_NOT_PERMITTED = 8 @@ -30,7 +30,8 @@ ERR_AUTH_KEY_NOT_PERMITTED = 8
err_msgs[ERR_INVALID_AUTH_KEY] = 'The given authentication key is invalid'
err_msgs[ERR_AUTH_KEY_LOCKED] = 'The given authentication key is locked'
err_msgs[ERR_AUTH_KEY_NOT_PERMITTED] = 'The given authentication key has insufficient permissions for this action'
err_msgs[ERR_AUTH_KEY_NOT_PERMITTED] = 'The given authentication key \
has insufficient permissions for this action'
#Errors for get_user_info
ERR_USER_NOT_FOUND = 11
@ -48,27 +49,33 @@ err_msgs[ERR_ITEM_NOT_FOUND] = 'Can\'t find the given item' @@ -48,27 +49,33 @@ err_msgs[ERR_ITEM_NOT_FOUND] = 'Can\'t find the given item'
ERR_ITEM_NOT_FOUND_ = 41
ERR_INSUFFICIENT_CREDIT = 42
err_msgs[ERR_ITEM_NOT_FOUND_] = 'At least one of the items to buy could not be found'
err_msgs[ERR_INSUFFICIENT_CREDIT] = 'The user has not enough money left to buy the specified items'
err_msgs[ERR_ITEM_NOT_FOUND_] = 'At least one of the items to buy could \
not be found'
err_msgs[ERR_INSUFFICIENT_CREDIT] = 'The user has not enough money left to \
buy the specified items'
#Errors for cash_prepaid_card
ERR_CASH_CODE_NOT_VALID = 51
err_msgs[ERR_CASH_CODE_NOT_VALID] = 'Given code can\'t be found or has already been used'
err_msgs[ERR_CASH_CODE_NOT_VALID] = 'Given code can\'t be found or has \
already been used'
#Errors for cash_[gs]et_config_key
ERR_CONFIG_TYPE_MISMATCH = 61
ERR_CONFIG_UNKNOWN_TYPE = 62
err_msgs[ERR_CONFIG_TYPE_MISMATCH] = 'Value in database doesn\'t match the datatype for that key'
err_msgs[ERR_CONFIG_UNKNOWN_TYPE] = 'Given value is neither int, bool, string nor float'
err_msgs[ERR_CONFIG_TYPE_MISMATCH] = 'Value in database doesn\'t match the \
datatype for that key'
err_msgs[ERR_CONFIG_UNKNOWN_TYPE] = 'Given value is neither int, bool, string \
nor float'
#Errors for cash_modify_credit
ERR_USER_NOT_FOUND__ = 71
ERR_USER_NOT_AUTHORIZED = 72
err_msgs[ERR_USER_NOT_FOUND] = 'User not found'
err_msgs[ERR_USER_NOT_AUTHORIZED] = 'User not authorized to change another user\'s credit'
err_msgs[ERR_USER_NOT_AUTHORIZED] = 'User not authorized to change another \
user\'s credit'
class ApiError(Exception):
def __init__(self, code):
@ -147,7 +154,8 @@ def cashapi(request): @@ -147,7 +154,8 @@ def cashapi(request):
item = Product.objects.get(pk = data['id'])
except KeyError:
try:
item = Product.objects.get(productbarcode__barcode = data['ean'])
item = Product.objects.get(productbarcode__barcode =
data['ean'])
except KeyError:
raise ApiError(ERR_PARAM)
except Product.DoesNotExist:
@ -191,7 +199,10 @@ def cashapi(request): @@ -191,7 +199,10 @@ def cashapi(request):
error = {'code': e.code, 'msg': err_msgs[e.code]}
# Generate return object
ret = {'err_code': error['code'], 'err_msg': error['msg'], 'return_values': retval, 'api_version': API_VERSION}
ret = {'err_code': error['code'],
'err_msg': error['msg'],
'return_values': retval,
'api_version': API_VERSION}
print ret

Loading…
Cancel
Save