Skip to content

Commit

Permalink
Merge pull request #3303 from fecgov/feature/fix_elections_per_page
Browse files Browse the repository at this point in the history
Fix elections endpoint to handle per_page=0
  • Loading branch information
lbeaufort authored Jul 24, 2018
2 parents b4ede71 + 745aa4d commit 01286cb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions webservices/resources/elections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from webservices import utils
from webservices import filters
from webservices import schemas
from webservices.common import counts
from webservices.utils import use_kwargs
from webservices.common import models
from webservices.common.views import ApiResource
Expand Down Expand Up @@ -128,6 +129,19 @@ def args(self):
),
)

def get(self, *args, **kwargs):
query = self.build_query(*args, **kwargs)
count = counts.count_estimate(query, models.db.session, threshold=500000)
multi = False
if isinstance(kwargs['sort'], (list, tuple)):
multi = True

return utils.fetch_page(
query, kwargs,
count=count, model=self.model, join_columns=self.join_columns, aliases=self.aliases,
index_column=self.index_column, cap=0, multi=multi,
)

def build_query(self, **kwargs):
utils.check_election_arguments(kwargs)
totals_model = office_totals_map[kwargs['office']]
Expand Down

0 comments on commit 01286cb

Please sign in to comment.