def get(self, external_key=None, enrollment_type=None, state=None, **kwargs): if state: state = [x.strip() for x in state.split(',')] state = [Enrollment.ENROLLMENT_STATUS_CHOICES_REVERSE.get(s, s) for s in state if s] enrollments = Enrollment.list(external_key=external_key, enrollment_type=enrollment_type, state=state) query_filter = current_enrollments.list_permission_filter enrollments = query_filter(enrollments) pagination = Pagination(current_app, db) return pagination.paginate(enrollments, self.enrollment_fields, post_query_hook=lambda l: NeverEmptyList(l))
def get_page_requests(page): ''' Function to fetch and return all feature requests ''' app.app.config['PAGINATE_PAGE_SIZE'] = ROWS_PER_PAGE pagination = Pagination(app.app, db) schema = { 'name': fields.String, 'description': fields.String, 'date': fields.String, 'priority': fields.Integer, 'client': fields.String, 'productarea': fields.String } return pagination.paginate(FeatureRequest, schema)
from resources.mall import Mall, MallList from resources.account import Account, AccountList, AccountPost from resources.unit import UnitId, UnitPost, UnitList from db import db app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data_app.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['PROPAGATE_EXCEPTIONS'] = True api = Api(app) db.init_app(app) # Configurations for Paginate # app.config['PAGINATE_PAGE_SIZE'] = 5 pagination = Pagination(app, db) @app.before_first_request def create_tables(): """Create our data base.""" db.create_all() @app.route('/') def get_stores(): """Welcome massage.""" return "Welcome to this fantastic app!" # Endpoints that can accept multiple resources in a single call.
from flask_bcrypt import Bcrypt from flask_cors import CORS from flask_jwt_extended import JWTManager from flask_mail import Mail from flask_marshmallow import Marshmallow from flask_migrate import Migrate from flask_redis import FlaskRedis from flask_rest_paginate import Pagination from flask_rq2 import RQ from flask_sqlalchemy import SQLAlchemy jwt = JWTManager() db = SQLAlchemy() rq = RQ() mail = Mail() migrate = Migrate() ma = Marshmallow() bcrypt = Bcrypt() pagination = Pagination() cors = CORS() redis = FlaskRedis()
from flask_rest_paginate import Pagination from marshmallow import Schema, fields """ Initialize the app """ app = Flask(__name__) api = Api(app) # Possible configurations for Paginate # app.config['PAGINATE_PAGE_SIZE'] = 20 # app.config['PAGINATE_PAGE_PARAM'] = "pagenumber" # app.config['PAGINATE_SIZE_PARAM'] = "pagesize" # app.config['PAGINATE_RESOURCE_LINKS_ENABLED'] = False # app.config['PAGINATE_PAGINATION_OBJECT_KEY'] = "pagination" # app.config['PAGINATE_DATA_OBJECT_KEY'] = "data" pagination = Pagination(app) class CalculationSchema(Schema): calculation_time = fields.Str() value = fields.Str() """ Controllers """ class CalculationList(Resource): def get(self): """