Skip to content

Commit

Permalink
Merge pull request #5509 from fecgov/feature/5479-status-code-for-inv…
Browse files Browse the repository at this point in the history
…alid-sort-option

Add validation to sorting option
  • Loading branch information
pkfec authored Jul 31, 2023
2 parents b121272 + 7132dc9 commit ce063d4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion webservices/resources/candidate_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,27 @@ class TotalsCandidateView(ApiResource):
schema = schemas.CandidateHistoryTotalSchema
page_schema = schemas.CandidateHistoryTotalPageSchema

sort_options = [
'election_year',
'name',
'party',
'state',
'office',
'district',
'receipts',
'disbursements',
]

@property
def args(self):
return utils.extend(args.paging, args.candidate_totals, args.make_sort_args(),)
return utils.extend(
args.paging,
args.candidate_totals,
args.make_sort_args(
default='-election_year',
validator=args.OptionValidator(self.sort_options)
),
)

def filter_multi_fields(self, history, total):
return [
Expand Down

0 comments on commit ce063d4

Please sign in to comment.