From 6c3f73cd753ea2dad51bbf6ff47f67efd38644bb Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 19 May 2017 16:48:47 +0200 Subject: [PATCH] User __dict__.get to avoid long lines. --- accountant/views/accounts.py | 4 ++-- accountant/views/operations.py | 4 ++-- accountant/views/scheduled_operations.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/accountant/views/accounts.py b/accountant/views/accounts.py index 32de41c..2e92125 100644 --- a/accountant/views/accounts.py +++ b/accountant/views/accounts.py @@ -148,7 +148,7 @@ class AccountListResource(Resource): data = self.api.payload # A new account MUST NOT have an id; - if 'id' in data and data['id']: + if data.get('id') is not None: ns.abort(406, 'Id must not be provided on creation.') # Instantiate account with data. @@ -203,7 +203,7 @@ class AccountResource(Resource): data = self.api.payload # Check ID consistency. - if 'id' in data and data['id'] and data['id'] != account_id: + if data.get('id', default=account_id) != account_id: ns.abort(406, 'Id must not be provided or changed on update.') # Need to get the object to update it. diff --git a/accountant/views/operations.py b/accountant/views/operations.py index cc0cc5f..b21c513 100644 --- a/accountant/views/operations.py +++ b/accountant/views/operations.py @@ -132,7 +132,7 @@ class OperationListResource(Resource): ns.abort(404, 'Account with id %d not found.' % account_id) # A new operation MUST NOT have an id; - if 'id' in data and data['id']: + if data.get('id') is not None: ns.abort(406, 'Id must not be provided on creation.') operation = Operation(**data) @@ -181,7 +181,7 @@ class OperationResource(Resource): data = self.api.payload # Check ID consistency. - if 'id' in data and data['id'] and data['id'] != operation_id: + if data.get('id', default=operation_id) != operation_id: ns.abort(406, 'Id must not be provided or changed on update.') # pylint: disable=no-member diff --git a/accountant/views/scheduled_operations.py b/accountant/views/scheduled_operations.py index b73c992..2f48461 100644 --- a/accountant/views/scheduled_operations.py +++ b/accountant/views/scheduled_operations.py @@ -106,7 +106,7 @@ class ScheduledOperationListResource(Resource): ns.abort(404, 'Account with id %d not found.' % account_id) # A new scheduled operation MUST NOT have an id; - if 'id' in data and data['id']: + if data.get('id') is not None: ns.abort(406, 'Id must not be provided on creation.') scheduled_operation = ScheduledOperation(**data) @@ -160,7 +160,7 @@ class ScheduledOperationResource(Resource): so_id = scheduled_operation_id # Check ID consistency. - if 'id' in data and data['id'] and data['id'] != so_id: + if data.get('id', default=so_id) != so_id: ns.abort(406, 'Id must not be provided or changed on update.') scheduled_operation = ScheduledOperation.query().get(so_id)