def get(self, **kwargs): committee_id = kwargs['id'] args = self.parser.parse_args(strict=True) # pagination page_num = args.get('page', 1) per_page = args.get('per_page', 20) page_data = Pagination(page_num, per_page, 1) committee = Committee.query.filter_by(committee_id=committee_id).one() totals_class, specific_fields = totals_model_map.get( committee.committee_type, totals_model_map['default'], ) results_fields = merge_dicts(common_fields, specific_fields) totals = self.get_totals(committee_id, totals_class, args, page_num, per_page) data = { 'api_version': '0.2', 'pagination': page_data.as_json(), 'results': totals } totals_view_fields = { 'api_version': fields.Fixed(1), 'pagination': fields.Nested(pagination_fields), 'results': fields.Nested(results_fields), } return marshal(data, totals_view_fields)
def get(self, **kwargs): committee_id = kwargs['id'] args = self.parser.parse_args(strict=True) # pagination page_num = args.get('page', 1) per_page = args.get('per_page', 20) count = 1 committee = Committee.query.filter_by(committee_id=committee_id).one() if committee.committee_type == 'P': totals_class = CommitteeTotalsPresidential results_fields = merge_dicts(common_fields, presidential_fields) elif committee.committee_type in ['H', 'S']: totals_class = CommitteeTotalsHouseOrSenate results_fields = merge_dicts(common_fields, house_senate_fields) else: totals_class = CommitteeTotalsPacOrParty results_fields = merge_dicts(common_fields, pac_party_fields) totals = self.get_totals(committee_id, totals_class, args, page_num, per_page) data = { 'api_version': '0.2', 'pagination': { 'page': page_num, 'per_page': per_page, 'count': count, 'pages': ceil(count / per_page), }, 'results': totals } totals_view_fields = { 'api_version': fields.Fixed(1), 'pagination': fields.Nested(pagination_fields), 'results': fields.Nested(results_fields), } return marshal(data, totals_view_fields)
def get(self, **kwargs): committee_id = kwargs['id'] args = self.parser.parse_args(strict=True) # pagination page_num = args.get('page', 1) per_page = args.get('per_page', 20) committee = Committee.query.filter_by(committee_id=committee_id).one() if committee.committee_type == 'P': reports_class = CommitteeReportsPresidential results_fields = merge_dicts(common_fields, presidential_fields) elif committee.committee_type in ['H', 'S']: reports_class = CommitteeReportsHouseOrSenate results_fields = merge_dicts(common_fields, house_senate_fields) else: reports_class = CommitteeReportsPacOrParty results_fields = merge_dicts(common_fields, pac_party_fields) count, reports = self.get_reports(committee_id, reports_class, args, page_num, per_page) page_data = Pagination(page_num, per_page, count) data = { 'api_version': '0.2', 'pagination': page_data.as_json(), 'results': reports } reports_view_fields = { 'api_version': fields.Fixed(1), 'pagination': fields.Nested(pagination_fields), 'results': fields.Nested(results_fields), } return marshal(data, reports_view_fields)
'address_city': fields.String, 'address_state': fields.String, 'address_street_1': fields.String, 'address_street_2': fields.String, 'address_zip': fields.String, 'candidate_inactive': fields.String, 'committees': fields.Nested(candidate_commitee_fields), } pagination_fields = { 'per_page': fields.Integer, 'page': fields.Integer, 'count': fields.Integer, 'pages': fields.Integer, } candidate_list_fields = { 'api_version': fields.Fixed(1), 'pagination': fields.Nested(pagination_fields), 'results': fields.Nested(candidate_fields), } class CandidateList(Resource): parser = reqparse.RequestParser() parser.add_argument('q', type=str, help='Text to search all fields for') parser.add_argument('candidate_id', type=str, help="Candidate's FEC ID") parser.add_argument('fec_id', type=str, help="Candidate's FEC ID") parser.add_argument( 'page', type=inputs.natural, default=1, help='For paginating through results, starting at page 1')