Пример #1
0
    def get_candidates(self, kwargs):

        candidates = self.query

        if kwargs.get('q'):
            candidates = utils.search_text(
                candidates.join(
                    models.CandidateSearch,
                    models.Candidate.candidate_id == models.CandidateSearch.id,
                ),
                models.CandidateSearch.fulltxt,
                kwargs['q'],
            ).distinct()

        candidates = filter_query(models.Candidate, candidates, filter_fields,
                                  kwargs)

        if kwargs.get('name'):
            candidates = candidates.filter(
                models.Candidate.name.ilike('%{}%'.format(kwargs['name'])))

        # TODO(jmcarp) Reintroduce year filter pending accurate `load_date` and `expire_date` values
        if kwargs.get('cycle'):
            candidates = candidates.filter(
                models.Candidate.cycles.overlap(kwargs['cycle']))

        return candidates
Пример #2
0
    def get_committees(self, kwargs):

        committees = models.Committee.query

        if kwargs['candidate_id']:
            committees = committees.filter(
                models.Committee.candidate_ids.overlap(kwargs['candidate_id'])
            )

        if kwargs.get('q'):
            committees = utils.search_text(
                committees.join(
                    models.CommitteeSearch,
                    models.Committee.committee_id == models.CommitteeSearch.id,
                ),
                models.CommitteeSearch.fulltxt,
                kwargs['q'],
            )

        if kwargs.get('name'):
            committees = committees.filter(models.Committee.name.ilike('%{}%'.format(kwargs['name'])))

        committees = filter_query(models.Committee, committees, list_filter_fields, kwargs)

        if kwargs['year']:
            committees = filter_year(models.Committee, committees, kwargs['year'])

        if kwargs['cycle']:
            committees = committees.filter(models.Committee.cycles.overlap(kwargs['cycle']))

        return committees
Пример #3
0
    def get_candidate(self, kwargs, candidate_id=None, committee_id=None):
        if candidate_id is not None:
            candidates = models.CandidateDetail.query
            candidates = candidates.filter_by(candidate_id=candidate_id)

        if committee_id is not None:
            candidates = models.CandidateDetail.query.join(
                models.CandidateCommitteeLink
            ).filter(
                models.CandidateCommitteeLink.committee_id == committee_id
            ).distinct()

        candidates = filter_query(models.CandidateDetail, candidates, filter_fields, kwargs)

        # TODO(jmcarp) Reintroduce year filter pending accurate `load_date` and `expire_date` values
        if kwargs.get('cycle'):
            candidates = candidates.filter(models.CandidateDetail.cycles.overlap(kwargs['cycle']))

        return candidates
Пример #4
0
    def get_candidate(self, kwargs, candidate_id=None, committee_id=None):
        if candidate_id is not None:
            candidates = models.CandidateDetail.query
            candidates = candidates.filter_by(candidate_id=candidate_id)

        if committee_id is not None:
            candidates = models.CandidateDetail.query.join(
                models.CandidateCommitteeLink
            ).filter(
                models.CandidateCommitteeLink.committee_id == committee_id
            )

        candidates = filter_query(models.CandidateDetail, candidates, filter_fields, kwargs)

        # TODO(jmcarp) Reintroduce year filter pending accurate `load_date` and `expire_date` values
        if kwargs['cycle']:
            candidates = candidates.filter(models.CandidateDetail.cycles.overlap(kwargs['cycle']))

        return candidates
Пример #5
0
    def get_candidates(self, kwargs):

        candidates = self.query

        if kwargs.get("q"):
            candidates = utils.search_text(
                candidates.join(models.CandidateSearch, models.Candidate.candidate_id == models.CandidateSearch.id),
                models.CandidateSearch.fulltxt,
                kwargs["q"],
            ).distinct()

        candidates = filter_query(models.Candidate, candidates, filter_fields, kwargs)

        if kwargs.get("name"):
            candidates = candidates.filter(models.Candidate.name.ilike("%{}%".format(kwargs["name"])))

        # TODO(jmcarp) Reintroduce year filter pending accurate `load_date` and `expire_date` values
        if kwargs.get("cycle"):
            candidates = candidates.filter(models.Candidate.cycles.overlap(kwargs["cycle"]))

        return candidates
Пример #6
0
    def get_committee(self, kwargs, committee_id, candidate_id):

        committees = models.CommitteeDetail.query

        if committee_id is not None:
            committees = committees.filter_by(committee_id=committee_id)

        if candidate_id is not None:
            committees = models.CommitteeDetail.query.join(
                models.CandidateCommitteeLink
            ).filter(
                models.CandidateCommitteeLink.candidate_id == candidate_id
            ).distinct()

        committees = filter_query(models.CommitteeDetail, committees, detail_filter_fields, kwargs)

        if kwargs.get('year'):
            committees = filter_year(models.CommitteeDetail, committees, kwargs['year'])

        if kwargs.get('cycle'):
            committees = committees.filter(models.CommitteeDetail.cycles.overlap(kwargs['cycle']))

        return committees
Пример #7
0
    def get_committee(self, kwargs, committee_id, candidate_id):

        committees = models.CommitteeDetail.query

        if committee_id is not None:
            committees = committees.filter_by(committee_id=committee_id)

        if candidate_id is not None:
            committees = models.CommitteeDetail.query.join(
                models.CandidateCommitteeLink
            ).filter(
                models.CandidateCommitteeLink.candidate_id == candidate_id
            )

        committees = filter_query(models.CommitteeDetail, committees, detail_filter_fields, kwargs)

        if kwargs['year']:
            committees = filter_year(models.CommitteeDetail, committees, kwargs['year'])

        if kwargs['cycle']:
            committees = committees.filter(models.CommitteeDetail.cycles.overlap(kwargs['cycle']))

        return committees
Пример #8
0
    def get_candidates(self, kwargs):

        candidates = self.query

        if kwargs.get('q'):
            candidates = utils.search_text(
                candidates.join(
                    models.CandidateSearch,
                    models.Candidate.candidate_id == models.CandidateSearch.id,
                ),
                models.CandidateSearch.fulltxt,
                kwargs['q'],
            )

        candidates = filter_query(models.Candidate, candidates, filter_fields, kwargs)

        if kwargs.get('name'):
            candidates = candidates.filter(models.Candidate.name.ilike('%{}%'.format(kwargs['name'])))

        # TODO(jmcarp) Reintroduce year filter pending accurate `load_date` and `expire_date` values
        if kwargs['cycle']:
            candidates = candidates.filter(models.Candidate.cycles.overlap(kwargs['cycle']))

        return candidates
Пример #9
0
 def get(self, **kwargs):
     query = self.model.query
     query = filter_query(self.model, query, self.filter_fields, kwargs)
     query = filter_upcoming(query, self.date_column, kwargs)
     return utils.fetch_page(query, kwargs, model=self.model)
Пример #10
0
 def get(self, **kwargs):
     query = self.model.query
     query = filter_query(self.model, query, self.filter_fields, kwargs)
     query = filter_upcoming(query, self.date_column, kwargs)
     return utils.fetch_page(query, kwargs, model=self.model)
Пример #11
0
 def get(self, **kwargs):
     query = models.Filings.query
     query = filter_query(models.Filings, query, fields, kwargs)
     query = utils.filter_range(query, kwargs, range_fields)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(query, kwargs, model=models.Filings, count=count)