From 14498f2b48e8c963464bc55b28142480e5f00cd2 Mon Sep 17 00:00:00 2001 From: Priyanka Kasireddy Date: Wed, 28 Nov 2018 15:07:05 -0500 Subject: [PATCH 1/3] Add support-oppose-indicator to sort args function, which makes this column sortable. This gives the ability to sort by this column from the IE data pages on the frontend. --- webservices/args.py | 4 ++++ webservices/resources/sched_e.py | 1 + 2 files changed, 5 insertions(+) diff --git a/webservices/args.py b/webservices/args.py index 893327c19..fa0135394 100644 --- a/webservices/args.py +++ b/webservices/args.py @@ -767,6 +767,10 @@ def make_seek_args(field=fields.Int, description=None): IStr(validate=validate.OneOf(['S', 'O'])), description='Support or opposition', ), + 'last_support_oppose_indicator': fields.Str(missing=None, + description='When sorting by `support_oppose_indicator`,' + 'this is populated with the `support_oppose_indicator` of the last result.' + 'However, you will need to pass the index of that last result to `last_index` to get the next page.'), 'is_notice': fields.List(fields.Bool, description='Record filed as 24- or 48-hour notice'), } diff --git a/webservices/resources/sched_e.py b/webservices/resources/sched_e.py index 9d0c176b0..9d2d36eda 100644 --- a/webservices/resources/sched_e.py +++ b/webservices/resources/sched_e.py @@ -76,6 +76,7 @@ def args(self): 'expenditure_date', 'expenditure_amount', 'office_total_ytd', + 'support_oppose_indicator' ]), ), ) From df5fda3c14b10f0e9039b22b8df5d372dbc26505 Mon Sep 17 00:00:00 2001 From: Priyanka Kasireddy Date: Fri, 30 Nov 2018 11:40:13 -0500 Subject: [PATCH 2/3] Add tests to sort support/oppose column by asc/desc order on SE endpoint. --- tests/test_itemized.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_itemized.py b/tests/test_itemized.py index 6e0dbb859..b5d609bdf 100644 --- a/tests/test_itemized.py +++ b/tests/test_itemized.py @@ -741,3 +741,23 @@ def test_filters_sched_e_efile(self): results = self._results(api.url_for(ScheduleEEfileView, **{label: values[0]})) assert len(results) == 1 assert results[0][column.key] == values[0] + + def test_schedule_e_sort_args_descending(self): + [ + factories.ScheduleEFactory(expenditure_amount=100, expenditure_date=datetime.date(2016, 1, 1), + committee_id='101', support_oppose_indicator='s'), + factories.ScheduleEFactory(expenditure_amount=100, expenditure_date=datetime.date(2016, 1, 1), + committee_id='101', support_oppose_indicator='o'), + ] + results = self._results(api.url_for(ScheduleEView, sort='-support_oppose_indicator')) + self.assertEqual(results[0]['support_oppose_indicator'], 's') + + def test_schedule_e_sort_args_ascending(self): + [ + factories.ScheduleEFactory(expenditure_amount=100, expenditure_date=datetime.date(2016, 1, 1), + committee_id='101', support_oppose_indicator='s'), + factories.ScheduleEFactory(expenditure_amount=100, expenditure_date=datetime.date(2016, 1, 1), + committee_id='101', support_oppose_indicator='o'), + ] + results = self._results(api.url_for(ScheduleEView, sort='support_oppose_indicator')) + self.assertEqual(results[0]['support_oppose_indicator'], 'o') From 594e9ce01cc7f42aa9f6c62af0e8a2053ad597ea Mon Sep 17 00:00:00 2001 From: Priyanka Kasireddy Date: Mon, 3 Dec 2018 13:23:02 -0500 Subject: [PATCH 3/3] Move the schedule_e args column description to docs.py --- webservices/args.py | 28 ++++++++++------------------ webservices/docs.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/webservices/args.py b/webservices/args.py index fa0135394..603884ca7 100644 --- a/webservices/args.py +++ b/webservices/args.py @@ -742,36 +742,28 @@ def make_seek_args(field=fields.Int, description=None): } schedule_e = { - 'candidate_office': fields.List(fields.Str(validate=validate.OneOf(['', 'H', 'S', 'P'])), description=docs.OFFICE), + 'candidate_office': fields.List(fields.Str(validate=validate.OneOf(['', 'H', 'S', 'P'])), + description=docs.OFFICE), 'candidate_party': fields.List(IStr, description=docs.PARTY), 'candidate_office_state': fields.List(IStr, description=docs.STATE_GENERIC), 'candidate_office_district': fields.List(District, description=docs.DISTRICT), 'cycle': fields.List(fields.Int, description=docs.RECORD_CYCLE), 'committee_id': fields.List(IStr, description=docs.COMMITTEE_ID), 'candidate_id': fields.List(IStr, description=docs.CANDIDATE_ID), - 'filing_form': fields.List(IStr, description='Filing form'), + 'filing_form': fields.List(IStr, description=docs.FORM_TYPE), 'last_expenditure_date': fields.Date(missing=None, - description='When sorting by `expenditure_date`,' - 'this is populated with the `expenditure_date` of the last result.' - 'However, you will need to pass the index of that last result to `last_index` to get the next page.'), + description=docs.LAST_EXPENDITURE_DATE), 'last_expenditure_amount': fields.Float(missing=None, - description='When sorting by `expenditure_amount`,' - 'this is populated with the `expenditure_amount` of the last result.' - 'However, you will need to pass the index of that last result to `last_index` to get the next page.'), + description=docs.LAST_EXPENDITURE_AMOUNT), 'last_office_total_ytd': fields.Float(missing=None, - description='When sorting by `office_total_ytd`,' - 'this is populated with the `office_total_ytd` of the last result.' - 'However, you will need to pass the index of that last result to `last_index` to get the next page.'), - 'payee_name': fields.List(fields.Str, description='Name of the entity that received the payment'), + description=docs.LAST_OFFICE_TOTAL_YTD), + 'payee_name': fields.List(fields.Str, description=docs.PAYEE_NAME), 'support_oppose_indicator': fields.List( IStr(validate=validate.OneOf(['S', 'O'])), - description='Support or opposition', - ), + description=docs.SUPPORT_OPPOSE_INDICATOR), 'last_support_oppose_indicator': fields.Str(missing=None, - description='When sorting by `support_oppose_indicator`,' - 'this is populated with the `support_oppose_indicator` of the last result.' - 'However, you will need to pass the index of that last result to `last_index` to get the next page.'), - 'is_notice': fields.List(fields.Bool, description='Record filed as 24- or 48-hour notice'), + description=docs.LAST_SUPPOSE_OPPOSE_INDICATOR), + 'is_notice': fields.List(fields.Bool, description=docs.IS_NOTICE), } schedule_e_efile = { diff --git a/webservices/docs.py b/webservices/docs.py index f13966455..6829d82a5 100644 --- a/webservices/docs.py +++ b/webservices/docs.py @@ -1286,3 +1286,40 @@ def add_ytd(var): MAX_TRANSACTION_DATA_COMPLETE_DATE = ''' Select all filings processed completely before this date ''' + +LAST_EXPENDITURE_DATE = ''' +When sorting by `expenditure_date`, +this is populated with the `expenditure_date` of the last result. +However, you will need to pass the index of that last result to +`last_index` to get the next page. +''' + +LAST_EXPENDITURE_AMOUNT = ''' +When sorting by `expenditure_amount`, +this is populated with the `expenditure_amount` of the last result. +However, you will need to pass the index of that last result to +`last_index` to get the next page. +''' +LAST_OFFICE_TOTAL_YTD = ''' +When sorting by `office_total_ytd`, +this is populated with the `office_total_ytd` of the last result. +However, you will need to pass the index of that last result to +`last_index` to get the next page.' +''' + +LAST_SUPPOSE_OPPOSE_INDICATOR = ''' +When sorting by `support_oppose_indicator`, +this is populated with the `support_oppose_indicator` of the last result. +However, you will need to pass the index of that last result to `last_index` +to get the next page.' +''' + +PAYEE_NAME = ''' +Name of the entity that received the payment. +''' +IS_NOTICE = ''' +Record filed as 24- or 48-hour notice. +''' +filing_form = ''' +The form type filed by the canidate of committee +'''