Exemplo n.º 1
0
def initialize(app):
    api = APIManager(app, flask_sqlalchemy_db=app.db)

    blueprints = [
        api.create_api_blueprint(
            m.Account,
            methods=['GET', 'POST', 'PUT'],
            results_per_page=None,
        ),
        api.create_api_blueprint(
            m.Payee,
            methods=['GET', 'POST'],
            results_per_page=None,
        ),
        api.create_api_blueprint(
            m.Transaction,
            methods=['GET', 'POST', 'PUT'],
            results_per_page=25,
        ),
    ]

    map(app.register_blueprint, blueprints)
Exemplo n.º 2
0
from models import Admin, User, Experiment, ExperimentUser
from forms import LoginF
from mail import mail

# Setting the WebAPP

app = Flask('homepage')
app.register_blueprint(dashboardB,url_prefix='/dashboard')
app.register_blueprint(pollB)
app.register_blueprint(apiB,url_prefix='/api')

# Adding RESTful-Restless api
manager = APIManager(app, session=db_session)
api_experiment=manager.create_api_blueprint(
    Experiment,methods=['GET'],
    collection_name='experiment',
    include_columns=['status','id','name','description','date_creation','date_modification','users','definition']
)
app.register_blueprint(api_experiment,url_prefix='/api')
api_user=manager.create_api_blueprint(
    User,methods=['GET'],
    collection_name='user',
    include_columns=['accepted','confirmed','id','userid','email','previous','level','gender','year_birthday','experiments']
)
app.register_blueprint(api_user,url_prefix='/api')
api_experimentuser=manager.create_api_blueprint(
    ExperimentUser,methods=['GET'],
    collection_name='eu'
)
app.register_blueprint(api_experimentuser,url_prefix='/api')
Exemplo n.º 3
0

def verify_new_user(data):
    assert data["username"]
    assert data["password"]
    data["password"] = hash_password(data["password"])


def sanitize_user(result, **kwargs):
    del result["password"]


manager = APIManager(app, flask_sqlalchemy_db=db)

blueprints = [
    manager.create_api_blueprint(
        m.Person, methods=["GET", "POST", "PUT"], postprocessors={"POST": [person_created]}, results_per_page=None
    ),
    manager.create_api_blueprint(m.EmergencyContact, methods=["GET", "POST", "PUT", "DELETE"], results_per_page=None),
    manager.create_api_blueprint(m.Absence, methods=["GET", "POST", "PUT", "DELETE"], results_per_page=None),
    manager.create_api_blueprint(m.Document, methods=["GET", "PUT"], results_per_page=None),
    manager.create_api_blueprint(
        m.User, methods=["POST"], preprocessors={"POST": [verify_new_user]}, postprocessors={"POST": [sanitize_user]}
    ),
]

for b in blueprints:
    b.before_request(auth.login_required(lambda: None))

map(app.register_blueprint, blueprints)