Rename kwargs to data.
This commit is contained in:
parent
2e194fe550
commit
fe525dde46
@ -71,9 +71,9 @@ class AccountListResource(Resource):
|
||||
"""
|
||||
Create a new account.
|
||||
"""
|
||||
kwargs = parser.parse_args()
|
||||
data = parser.parse_args()
|
||||
|
||||
account = Account(**kwargs)
|
||||
account = Account(**data)
|
||||
|
||||
db.session.add(account)
|
||||
|
||||
@ -93,11 +93,11 @@ class AccountResource(Resource):
|
||||
"""
|
||||
Get account.
|
||||
"""
|
||||
kwargs = date_parser.parse_args()
|
||||
data = date_parser.parse_args()
|
||||
|
||||
try:
|
||||
return Account.query(
|
||||
**kwargs
|
||||
**data
|
||||
).filter(
|
||||
Account.id == id
|
||||
).one(), 200
|
||||
@ -107,10 +107,10 @@ class AccountResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(Object(resource_fields))
|
||||
def post(self, id):
|
||||
kwargs = parser.parse_args()
|
||||
data = parser.parse_args()
|
||||
|
||||
assert (id not in kwargs or kwargs.id is None
|
||||
or kwargs.id == id)
|
||||
assert (id not in data or data.id is None
|
||||
or data.id == id)
|
||||
|
||||
# Need to get the object to update it.
|
||||
account = db.session.query(Account).get(id)
|
||||
@ -119,7 +119,7 @@ class AccountResource(Resource):
|
||||
return None, 404
|
||||
|
||||
# SQLAlchemy objects ignore __dict__.update() with merge.
|
||||
for k, v in kwargs.items():
|
||||
for k, v in data.items():
|
||||
setattr(account, k, v)
|
||||
|
||||
db.session.merge(account)
|
||||
@ -164,9 +164,9 @@ class CategoriesResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(fields.List(Object(category_resource_fields)))
|
||||
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 = {
|
||||
@ -182,9 +182,9 @@ class SoldsResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(fields.List(Object(ohlc_resource_fields)))
|
||||
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")
|
||||
|
@ -67,21 +67,21 @@ class OperationListResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(fields.List(Object(resource_fields)))
|
||||
def get(self):
|
||||
kwargs = range_parser.parse_args()
|
||||
data = range_parser.parse_args()
|
||||
|
||||
return Operation.query(
|
||||
begin=kwargs['begin'],
|
||||
end=kwargs['end'],
|
||||
begin=data['begin'],
|
||||
end=data['end'],
|
||||
).filter(
|
||||
Operation.account_id == kwargs['account']
|
||||
Operation.account_id == data['account']
|
||||
).all(), 200
|
||||
|
||||
@requires_auth
|
||||
@marshal_with_field(Object(resource_fields))
|
||||
def post(self):
|
||||
kwargs = parser.parse_args()
|
||||
data = parser.parse_args()
|
||||
|
||||
operation = Operation(**kwargs)
|
||||
operation = Operation(**data)
|
||||
|
||||
db.session.add(operation)
|
||||
|
||||
@ -105,10 +105,10 @@ class OperationResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(Object(resource_fields))
|
||||
def post(self, id):
|
||||
kwargs = parser.parse_args()
|
||||
data = parser.parse_args()
|
||||
|
||||
assert (id not in kwargs or kwargs.id is None
|
||||
or kwargs.id == id)
|
||||
assert (id not in data or data.id is None
|
||||
or data.id == id)
|
||||
|
||||
operation = db.session.query(Operation).get(id)
|
||||
|
||||
@ -116,7 +116,7 @@ class OperationResource(Resource):
|
||||
return None, 404
|
||||
|
||||
# SQLAlchemy objects ignore __dict__.update() with merge.
|
||||
for k, v in kwargs.items():
|
||||
for k, v in data.items():
|
||||
setattr(operation, k, v)
|
||||
|
||||
db.session.merge(operation)
|
||||
|
@ -65,10 +65,10 @@ class ScheduledOperationListResource(Resource):
|
||||
"""
|
||||
Get all scheduled operation for the account.
|
||||
"""
|
||||
kwargs = get_parser.parse_args()
|
||||
data = get_parser.parse_args()
|
||||
|
||||
return ScheduledOperation.query().filter(
|
||||
ScheduledOperation.account_id == kwargs.account
|
||||
ScheduledOperation.account_id == data.account
|
||||
).all(), 200
|
||||
|
||||
@marshal_with_field(Object(resource_fields))
|
||||
@ -76,9 +76,9 @@ class ScheduledOperationListResource(Resource):
|
||||
"""
|
||||
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)
|
||||
|
||||
@ -107,10 +107,10 @@ class ScheduledOperationResource(Resource):
|
||||
"""
|
||||
Update a scheduled operation.
|
||||
"""
|
||||
kwargs = parser.parse_args()
|
||||
data = parser.parse_args()
|
||||
|
||||
assert (id not in kwargs or kwargs.id is None
|
||||
or kwargs.id == id)
|
||||
assert (id not in data or data.id is None
|
||||
or data.id == id)
|
||||
|
||||
try:
|
||||
scheduled_operation = ScheduledOperation.query().filter(
|
||||
@ -120,7 +120,7 @@ class ScheduledOperationResource(Resource):
|
||||
return None, 404
|
||||
|
||||
# SQLAlchemy objects ignore __dict__.update() with merge.
|
||||
for k, v in kwargs.items():
|
||||
for k, v in data.items():
|
||||
setattr(scheduled_operation, k, v)
|
||||
|
||||
db.session.merge(scheduled_operation)
|
||||
|
@ -47,14 +47,14 @@ def load_user_from_auth(auth):
|
||||
def load_user_from_request():
|
||||
# No token found, trying to authenticate using request data.
|
||||
try:
|
||||
kwargs = parser.parse_args()
|
||||
data = parser.parse_args()
|
||||
|
||||
try:
|
||||
user = User.query().filter(
|
||||
User.email == kwargs['email']
|
||||
User.email == data['email']
|
||||
).one()
|
||||
|
||||
if user and user.verify_password(kwargs['password']):
|
||||
if user and user.verify_password(data['password']):
|
||||
return user
|
||||
|
||||
except NoResultFound:
|
||||
@ -71,7 +71,7 @@ def authenticate():
|
||||
|
||||
def requires_auth(f):
|
||||
@wraps(f)
|
||||
def wrapped(*args, **kwargs):
|
||||
def wrapped(*args, **data):
|
||||
if 'Authorization' in request.headers:
|
||||
auth = request.headers['Authorization']
|
||||
user = load_user_from_auth(auth)
|
||||
@ -80,7 +80,7 @@ def requires_auth(f):
|
||||
|
||||
if user:
|
||||
g.user = user
|
||||
return f(*args, **kwargs)
|
||||
return f(*args, **data)
|
||||
|
||||
return authenticate()
|
||||
return wrapped
|
||||
|
Loading…
Reference in New Issue
Block a user