From e2c8a41ff6ce6b13fe06875349ae7860d290d257 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Tue, 12 Jan 2016 22:58:19 +0100 Subject: [PATCH] Order methods. --- accountant/api/views/accounts.py | 26 ++++----- accountant/api/views/scheduled_operations.py | 58 ++++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/accountant/api/views/accounts.py b/accountant/api/views/accounts.py index 14c51a2..ac192df 100644 --- a/accountant/api/views/accounts.py +++ b/accountant/api/views/accounts.py @@ -110,19 +110,6 @@ class AccountResource(Resource): except NoResultFound: return None, 404 - @requires_auth - @marshal_with_field(Object(resource_fields)) - def delete(self, id): - # Need to get the object to update it. - account = db.session.query(Account).get(id) - - if not account: - return None, 404 - - db.session.delete(account) - - return None, 204 - @requires_auth @marshal_with_field(Object(resource_fields)) def post(self, id): @@ -148,6 +135,19 @@ class AccountResource(Resource): Account.id == id ).one() + @requires_auth + @marshal_with_field(Object(resource_fields)) + def delete(self, id): + # Need to get the object to update it. + account = db.session.query(Account).get(id) + + if not account: + return None, 404 + + db.session.delete(account) + + return None, 204 + api_api.add_resource(AccountListResource, '/accounts') api_api.add_resource(AccountResource, '/accounts/') diff --git a/accountant/api/views/scheduled_operations.py b/accountant/api/views/scheduled_operations.py index 658477e..88e4168 100644 --- a/accountant/api/views/scheduled_operations.py +++ b/accountant/api/views/scheduled_operations.py @@ -102,35 +102,6 @@ class ScheduledOperationResource(Resource): except NoResultFound: return None, 404 - @marshal_with_field(Object(resource_fields)) - def delete(self, id): - """ - Delete a scheduled operation. - """ - try: - scheduled_operation = ScheduledOperation.query().filter( - ScheduledOperation.id == id - ).one() - except NoResultFound: - return None, 404 - - operations = scheduled_operation.operations.filter( - Operation.confirmed == true() - ).count() - - import ipdb; ipdb.set_trace() - - if operations: - return "There are still confirmed operations associated to this \ - scheduled operation.", 409 - - # Delete unconfirmed operations - operations = scheduled_operation.operations.delete() - - db.session.delete(scheduled_operation) - - return None, 204 - @marshal_with_field(Object(resource_fields)) def post(self, id): """ @@ -160,6 +131,35 @@ class ScheduledOperationResource(Resource): return scheduled_operation + @marshal_with_field(Object(resource_fields)) + def delete(self, id): + """ + Delete a scheduled operation. + """ + try: + scheduled_operation = ScheduledOperation.query().filter( + ScheduledOperation.id == id + ).one() + except NoResultFound: + return None, 404 + + operations = scheduled_operation.operations.filter( + Operation.confirmed == true() + ).count() + + import ipdb; ipdb.set_trace() + + if operations: + return "There are still confirmed operations associated to this \ + scheduled operation.", 409 + + # Delete unconfirmed operations + operations = scheduled_operation.operations.delete() + + db.session.delete(scheduled_operation) + + return None, 204 + api_api.add_resource(ScheduledOperationListResource, "/scheduled_operations") api_api.add_resource(ScheduledOperationResource,