Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable sort_nulls_last for Sch A and B #3494

Merged
merged 1 commit into from
Nov 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_itemized.py
Original file line number Diff line number Diff line change
@@ -637,6 +637,17 @@ def test_amount_sched_b(self):
results = self._results(api.url_for(ScheduleBView, min_amount=100, max_amount=150))
self.assertTrue(all(100 <= each['disbursement_amount'] <= 150 for each in results))

def test_sort_sched_b_ignores_nulls_last_parameter(self):
disbursements = [
factories.ScheduleBFactory(disbursement_amount=50),
factories.ScheduleBFactory(disbursement_amount=200, disbursement_date=datetime.date(2016, 3, 1)),
factories.ScheduleBFactory(disbursement_amount=150, disbursement_date=datetime.date(2016, 2, 1)),
factories.ScheduleBFactory(disbursement_amount=100, disbursement_date=datetime.date(2016, 1, 1)),
]
sub_ids = [str(each.sub_id) for each in disbursements]
results = self._results(api.url_for(ScheduleBView, sort='-disbursement_date', sort_nulls_last=True, **self.kwargs))
self.assertEqual([each['sub_id'] for each in results], sub_ids)

def test_amount_sched_e(self):
[
factories.ScheduleEFactory(expenditure_amount=50),
11 changes: 7 additions & 4 deletions webservices/args.py
Original file line number Diff line number Diff line change
@@ -118,8 +118,8 @@ def __call__(self, value):
)

def make_sort_args(default=None, validator=None, default_hide_null=False,
default_nulls_only=False, default_sort_nulls_last=False):
return {
default_nulls_only=False, default_sort_nulls_last=False, show_nulls_last_arg=True):
args = {
'sort': fields.Str(
missing=default,
validate=validator,
@@ -133,11 +133,14 @@ def make_sort_args(default=None, validator=None, default_hide_null=False,
missing=default_nulls_only,
description='Toggle that filters out all rows having sort column that is non-null'
),
'sort_nulls_last': fields.Bool(

}
if show_nulls_last_arg:
args['sort_nulls_last'] = fields.Bool(
missing=default_sort_nulls_last,
description='Toggle that sorts null values last'
)
}
return args


def make_multi_sort_args(default=None, validator=None, default_hide_null=False,
1 change: 1 addition & 0 deletions webservices/resources/sched_a.py
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@ def args(self):
'contribution_receipt_amount',
'contributor_aggregate_ytd',
]),
show_nulls_last_arg=False,
)
)

3 changes: 2 additions & 1 deletion webservices/resources/sched_b.py
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ def index_column(self):
('recipient_committee_id', models.ScheduleB.recipient_committee_id),
('disbursement_purpose_category', models.ScheduleB.disbursement_purpose_category),
('spender_committee_type', models.ScheduleB.spender_committee_type),

]
filter_match_fields = [
('two_year_transaction_period', models.ScheduleB.two_year_transaction_period),
@@ -59,6 +59,7 @@ def args(self):
args.make_sort_args(
default='-disbursement_date',
validator=args.OptionValidator(['disbursement_date', 'disbursement_amount']),
show_nulls_last_arg=False,
)
)