Exemple #1
0
class ScheduleAByStateCandidateTotalsView(utils.Resource):

    @use_kwargs(args.paging)
    @use_kwargs(args.make_sort_args())
    @use_kwargs(args.schedule_a_candidate_aggregate)
    @marshal_with(schemas.ScheduleAByStateCandidatePageSchema())
    def get(self, **kwargs):
        _, query = candidate_aggregate(
            ScheduleAByState,
            [
                ScheduleAByState.state,
                sa.func.sum(ScheduleAByState.total).label('total'),
                sa.func.max(ScheduleAByState.state_full).label('state_full'),
                ScheduleAByState.count,
            ],
            [
                ScheduleAByState.state, ScheduleAByState.count
            ],
            kwargs,
        )
        q = query.subquery()
        query = db.session.query(
            sa.func.sum(q.c.total).label('total'),
            sa.func.sum(q.c.count).label('count'),
            q.c.cand_id.label('candidate_id'),
            q.c.cycle
        ).group_by(q.c.cand_id, q.c.cycle)

        return utils.fetch_page(query, kwargs, cap=0)
Exemple #2
0
class ScheduleAByStateCandidateView(Resource):
    @args.register_kwargs(args.paging)
    @args.register_kwargs(args.make_sort_args())
    @args.register_kwargs(args.schedule_a_candidate_aggregate)
    @schemas.marshal_with(schemas.ScheduleAByStateCandidatePageSchema())
    def get(self, **kwargs):
        query = candidate_aggregate(
            ScheduleAByState,
            [
                ScheduleAByState.state,
                sa.func.max(ScheduleAByState.state_full).label('state_full'),
            ],
            [ScheduleAByState.state],
            kwargs,
        )
        return utils.fetch_page(query, kwargs, cap=0)
class ScheduleAByStateCandidateView(utils.Resource):
    @use_kwargs(args.paging)
    @use_kwargs(args.make_sort_args())
    @use_kwargs(args.schedule_a_candidate_aggregate)
    @marshal_with(schemas.ScheduleAByStateCandidatePageSchema())
    def get(self, **kwargs):
        _, query = candidate_aggregate(
            ScheduleAByState,
            [
                ScheduleAByState.state,
                sa.func.sum(ScheduleAByState.total).label('total'),
                sa.func.max(ScheduleAByState.state_full).label('state_full'),
                sa.func.sum(ScheduleAByState.count).label('count'),
            ],
            [ScheduleAByState.state],
            kwargs,
        )
        return utils.fetch_page(query, kwargs, cap=0)