From 4b1313e65c87c4c70fca068263f118b7693fe853 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 16 Jan 2016 18:38:10 +0100 Subject: [PATCH] Share account_id argument between parsers. --- accountant/api/views/parsers.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/accountant/api/views/parsers.py b/accountant/api/views/parsers.py index 08919ca..9209343 100644 --- a/accountant/api/views/parsers.py +++ b/accountant/api/views/parsers.py @@ -14,6 +14,7 @@ You should have received a copy of the GNU Affero General Public License along with Accountant. If not, see . """ +from copy import deepcopy import dateutil.parser from flask.ext.restful import reqparse @@ -29,9 +30,15 @@ range_parser.add_argument( type=lambda a: dateutil.parser.parse(a) if a else None ) +# Parser for an account id. +account_id_parser = reqparse.RequestParser() +account_id_parser.add_argument('account_id', type=int) + # Parser for a date range and an account id. account_range_parser = range_parser.copy() -account_range_parser.add_argument('account_id', type=int) +account_range_parser.add_argument( + deepcopy(account_id_parser.args[0]) +) # Parser for an account. account_parser = reqparse.RequestParser() @@ -53,10 +60,6 @@ operation_parser.add_argument('scheduled_operation_id', type=int) operation_parser.add_argument('confirmed', type=bool) operation_parser.add_argument('canceled', type=bool) -# Parser for an account id. -account_id_parser = reqparse.RequestParser() -account_id_parser.add_argument('account_id', type=int) - # Parser for a scheduled operation. scheduled_operation_parser = reqparse.RequestParser() scheduled_operation_parser.add_argument(