Rename kwargs to data.

This commit is contained in:
Alexis Lahouze 2016-01-12 23:24:46 +01:00
parent 2e194fe550
commit fe525dde46
4 changed files with 35 additions and 35 deletions

View File

@ -71,9 +71,9 @@ class AccountListResource(Resource):
""" """
Create a new account. Create a new account.
""" """
kwargs = parser.parse_args() data = parser.parse_args()
account = Account(**kwargs) account = Account(**data)
db.session.add(account) db.session.add(account)
@ -93,11 +93,11 @@ class AccountResource(Resource):
""" """
Get account. Get account.
""" """
kwargs = date_parser.parse_args() data = date_parser.parse_args()
try: try:
return Account.query( return Account.query(
**kwargs **data
).filter( ).filter(
Account.id == id Account.id == id
).one(), 200 ).one(), 200
@ -107,10 +107,10 @@ class AccountResource(Resource):
@requires_auth @requires_auth
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
def post(self, id): def post(self, id):
kwargs = parser.parse_args() data = parser.parse_args()
assert (id not in kwargs or kwargs.id is None assert (id not in data or data.id is None
or kwargs.id == id) or data.id == id)
# Need to get the object to update it. # Need to get the object to update it.
account = db.session.query(Account).get(id) account = db.session.query(Account).get(id)
@ -119,7 +119,7 @@ class AccountResource(Resource):
return None, 404 return None, 404
# SQLAlchemy objects ignore __dict__.update() with merge. # SQLAlchemy objects ignore __dict__.update() with merge.
for k, v in kwargs.items(): for k, v in data.items():
setattr(account, k, v) setattr(account, k, v)
db.session.merge(account) db.session.merge(account)
@ -164,9 +164,9 @@ class CategoriesResource(Resource):
@requires_auth @requires_auth
@marshal_with_field(fields.List(Object(category_resource_fields))) @marshal_with_field(fields.List(Object(category_resource_fields)))
def get(self): def get(self):
kwargs = range_parser.parse_args() data = range_parser.parse_args()
return Operation.get_categories_for_range(**kwargs).all(), 200 return Operation.get_categories_for_range(**data).all(), 200
ohlc_resource_fields = { ohlc_resource_fields = {
@ -182,9 +182,9 @@ class SoldsResource(Resource):
@requires_auth @requires_auth
@marshal_with_field(fields.List(Object(ohlc_resource_fields))) @marshal_with_field(fields.List(Object(ohlc_resource_fields)))
def get(self): def get(self):
kwargs = range_parser.parse_args() data = range_parser.parse_args()
return Operation.get_ohlc_per_day_for_range(**kwargs).all(), 200 return Operation.get_ohlc_per_day_for_range(**data).all(), 200
api_api.add_resource(CategoriesResource, "/categories") api_api.add_resource(CategoriesResource, "/categories")

View File

@ -67,21 +67,21 @@ class OperationListResource(Resource):
@requires_auth @requires_auth
@marshal_with_field(fields.List(Object(resource_fields))) @marshal_with_field(fields.List(Object(resource_fields)))
def get(self): def get(self):
kwargs = range_parser.parse_args() data = range_parser.parse_args()
return Operation.query( return Operation.query(
begin=kwargs['begin'], begin=data['begin'],
end=kwargs['end'], end=data['end'],
).filter( ).filter(
Operation.account_id == kwargs['account'] Operation.account_id == data['account']
).all(), 200 ).all(), 200
@requires_auth @requires_auth
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
def post(self): def post(self):
kwargs = parser.parse_args() data = parser.parse_args()
operation = Operation(**kwargs) operation = Operation(**data)
db.session.add(operation) db.session.add(operation)
@ -105,10 +105,10 @@ class OperationResource(Resource):
@requires_auth @requires_auth
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
def post(self, id): def post(self, id):
kwargs = parser.parse_args() data = parser.parse_args()
assert (id not in kwargs or kwargs.id is None assert (id not in data or data.id is None
or kwargs.id == id) or data.id == id)
operation = db.session.query(Operation).get(id) operation = db.session.query(Operation).get(id)
@ -116,7 +116,7 @@ class OperationResource(Resource):
return None, 404 return None, 404
# SQLAlchemy objects ignore __dict__.update() with merge. # SQLAlchemy objects ignore __dict__.update() with merge.
for k, v in kwargs.items(): for k, v in data.items():
setattr(operation, k, v) setattr(operation, k, v)
db.session.merge(operation) db.session.merge(operation)

View File

@ -65,10 +65,10 @@ class ScheduledOperationListResource(Resource):
""" """
Get all scheduled operation for the account. Get all scheduled operation for the account.
""" """
kwargs = get_parser.parse_args() data = get_parser.parse_args()
return ScheduledOperation.query().filter( return ScheduledOperation.query().filter(
ScheduledOperation.account_id == kwargs.account ScheduledOperation.account_id == data.account
).all(), 200 ).all(), 200
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
@ -76,9 +76,9 @@ class ScheduledOperationListResource(Resource):
""" """
Add a new scheduled operation. Add a new scheduled operation.
""" """
kwargs = parser.parse_args() data = parser.parse_args()
scheduled_operation = ScheduledOperation(**kwargs) scheduled_operation = ScheduledOperation(**data)
db.session.add(scheduled_operation) db.session.add(scheduled_operation)
@ -107,10 +107,10 @@ class ScheduledOperationResource(Resource):
""" """
Update a scheduled operation. Update a scheduled operation.
""" """
kwargs = parser.parse_args() data = parser.parse_args()
assert (id not in kwargs or kwargs.id is None assert (id not in data or data.id is None
or kwargs.id == id) or data.id == id)
try: try:
scheduled_operation = ScheduledOperation.query().filter( scheduled_operation = ScheduledOperation.query().filter(
@ -120,7 +120,7 @@ class ScheduledOperationResource(Resource):
return None, 404 return None, 404
# SQLAlchemy objects ignore __dict__.update() with merge. # SQLAlchemy objects ignore __dict__.update() with merge.
for k, v in kwargs.items(): for k, v in data.items():
setattr(scheduled_operation, k, v) setattr(scheduled_operation, k, v)
db.session.merge(scheduled_operation) db.session.merge(scheduled_operation)

View File

@ -47,14 +47,14 @@ def load_user_from_auth(auth):
def load_user_from_request(): def load_user_from_request():
# No token found, trying to authenticate using request data. # No token found, trying to authenticate using request data.
try: try:
kwargs = parser.parse_args() data = parser.parse_args()
try: try:
user = User.query().filter( user = User.query().filter(
User.email == kwargs['email'] User.email == data['email']
).one() ).one()
if user and user.verify_password(kwargs['password']): if user and user.verify_password(data['password']):
return user return user
except NoResultFound: except NoResultFound:
@ -71,7 +71,7 @@ def authenticate():
def requires_auth(f): def requires_auth(f):
@wraps(f) @wraps(f)
def wrapped(*args, **kwargs): def wrapped(*args, **data):
if 'Authorization' in request.headers: if 'Authorization' in request.headers:
auth = request.headers['Authorization'] auth = request.headers['Authorization']
user = load_user_from_auth(auth) user = load_user_from_auth(auth)
@ -80,7 +80,7 @@ def requires_auth(f):
if user: if user:
g.user = user g.user = user
return f(*args, **kwargs) return f(*args, **data)
return authenticate() return authenticate()
return wrapped return wrapped