Exemplo n.º 1
0
import datetime
import logging

from flask_restplus import Resource

from open_budget_data_api.api.restplus import api, paginate, page_of, page_args
from open_budget_data_api.api.serializers import exemption_item
from open_budget_data_api.models import Exemption

log = logging.getLogger(__name__)

ns = api.namespace('exemption', description='The Open Budget API : Exemption')


@ns.route('/publication/<int:publication_id>')
@api.expect(page_args, validate=False)
class ExemptionPublication(Resource):
    @api.marshal_with(exemption_item)
    @api.response(404, 'Exemption item not found.')
    def get(self, publication_id):
        """ Returns exemption for publication id. """
        return Exemption.query.filter(Exemption.publication_id == publication_id).first()


@ns.route('/entity/<entity_id>')
@api.expect(page_args, validate=False)
class ExemptionEntity(Resource):
    @api.marshal_with(exemption_item)
    @api.response(404, 'Exemption item not found.')
    def get(self, entity_id):
        """ Returns exemption for entity id. """
Exemplo n.º 2
0
import logging

from flask_restplus import Resource

from open_budget_data_api.api.restplus import api
from open_budget_data_api.api.serializers import entity_item
from open_budget_data_api.models import Entity

log = logging.getLogger(__name__)

ns = api.namespace('entity', description='The Open Budget API : Entity')


@ns.route('/<id>')
class EntityCode(Resource):
    @api.marshal_with(entity_item)
    @api.response(404, 'Entity item not found.')
    def get(self, id):
        """ Returns entity by id """
        return Entity.query.filter(Entity.id == id).first()
Exemplo n.º 3
0
import logging

from flask_restplus import Resource

from open_budget_data_api.api.restplus import api, paginate, page_args, page_of
from open_budget_data_api.api.serializers import changes_item
from open_budget_data_api.models import Changes

log = logging.getLogger(__name__)

ns = api.namespace('changes', description='The Open Budget API : Changes')


@ns.route('/<code>')
@api.expect(page_args, validate=False)
class ChangesCode(Resource):
    @api.marshal_with(page_of(changes_item))
    @api.response(404, 'Changes not found.')
    def get(self, code):
        """ Returns changes for code """
        return paginate(
            page_args,
            Changes.query.filter(Changes.budget_code == code).order_by(
                Changes.year.desc(), Changes.date.desc()))


@ns.route('/<code>/<int:year>')
@api.expect(page_args, validate=False)
class ChangesCodeYear(Resource):
    @api.marshal_with(page_of(changes_item))
    @api.response(404, 'Changes not found.')
import logging

from flask_restplus import Resource

from open_budget_data_api.api.restplus import api, paginate, page_args, page_of
from open_budget_data_api.api.serializers import procurement_item
from open_budget_data_api.models import Procurement

log = logging.getLogger(__name__)

ns = api.namespace('procurement',
                   description='The Open Budget API : Procurement')


@ns.route('/<code>')
@api.expect(page_args, validate=False)
class ProcurementBudget(Resource):
    @api.marshal_with(page_of(procurement_item))
    @api.response(404, 'Procurement item not found.')
    def get(self, code):
        """ Returns procurements for code. """
        return paginate(
            page_args,
            Procurement.query.filter(Procurement.budget_code == code))


@ns.route('/entity/<entity_id>')
@api.expect(page_args, validate=False)
class ProcurementEntity(Resource):
    @api.marshal_with(page_of(procurement_item))
    @api.response(404, 'Procurement item not found.')
import logging

from flask_restplus import Resource
from sqlalchemy.sql.expression import func

from open_budget_data_api.api.restplus import api, paginate, page_args, page_of
from open_budget_data_api.api.serializers import support_item
from open_budget_data_api.models import Support

log = logging.getLogger(__name__)

ns = api.namespace('supports', description='The Open Budget API : Supports')


@ns.route('/<code>')
@api.expect(page_args, validate=False)
class SupportCode(Resource):
    @api.marshal_with(page_of(support_item))
    @api.response(404, 'Support item not found.')
    def get(self, code):
        """ Returns supports for code prefix. """
        return paginate(
            page_args,
            Support.query.filter(Support.code.like(code + '%')).order_by(
                Support.year))


@ns.route('/<code>/<int:year>')
@api.expect(page_args, validate=False)
class SupportCodeYear(Resource):
    @api.marshal_with(page_of(support_item))