def init_extensions(app): db.init_app(app) db.app = app db.metadata.naming_convention = { "ix": 'ix_%(column_0_label)s', "uq": "uq_%(table_name)s_%(column_0_name)s", "ck": "ck_%(table_name)s_%(column_0_name)s", "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", "pk": "pk_%(table_name)s" } # set constraint naming convention to sensible default, per # http://docs.sqlalchemy.org/en/rel_0_9/core/constraints.html#configuring-constraint-naming-conventions assets.init_app(app) assets.app = app babel.init_app(app) cache.init_app(app) csrf.init_app(app) mail.init_app(app) login_manager.init_app(app) store.init_app(app) rest.init_app(app, flask_sqlalchemy_db=db, preprocessors=restless_preprocessors) rest.app = app if app.config.get('DEBUG'): from flask_debugtoolbar import DebugToolbarExtension DebugToolbarExtension(app)
def init_extensions(app): db.init_app(app) db.app = app db.metadata.naming_convention = { "ix": 'ix_%(column_0_label)s', "uq": "uq_%(table_name)s_%(column_0_name)s", "ck": "ck_%(table_name)s_%(column_0_name)s", "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", "pk": "pk_%(table_name)s" } # set constraint naming convention to sensible default, per # http://docs.sqlalchemy.org/en/rel_0_9/core/constraints.html#configuring-constraint-naming-conventions assets.init_app(app) assets.app = app babel.init_app(app) cache.init_app(app) csrf.init_app(app) mail.init_app(app) login_manager.init_app(app) rq.init_app(app) app.rq = rq store.init_app(app) rest.init_app(app, flask_sqlalchemy_db=db, preprocessors=restless_preprocessors) rest.app = app limiter.init_app(app) for handler in app.logger.handlers: limiter.logger.addHandler(handler) if app.config.get('DEBUG'): from flask_debugtoolbar import DebugToolbarExtension DebugToolbarExtension(app) app.debug = True
def configure_extensions(app): # I18N babel.init_app(app) # Database db.init_app(app) # CouchDB couchdbmanager.setup(app) couchdbmanager.sync(app) # Login login_manager.init_app(app) login_manager.login_view = "authentification.login" # Roles principal.init_app(app) # Mail mail.init_app(app) # Plugins list global plugin_manager.init_plugin_manager(app.root_path + "/plugins", app) plugin_manager.activate_plugins() plugin_manager.setup_plugins()
def create_app(): load_dotenv(".env", verbose=True) app = Flask(__name__) app.config.from_object("default_config") app.config.from_envvar("APPLICATION_SETTINGS") api = Api(app) @app.errorhandler(ValidationError) def handle_marshmallow_validation(err): return jsonify(err.messages), 400 @app.before_first_request def create_tables(): db.create_all() db.init_app(app) ma.init_app(app) login_manager.init_app(app) # authorize.init_app(app) jwt.init_app(app) babel.init_app(app) # Set up Casbin model config app.config['CASBIN_MODEL'] = './src/casbinmodel.conf' # Set headers where owner for enforcement policy should be located app.config['CASBIN_OWNER_HEADERS'] = {'Authorization'} # Set up Casbin Adapter adapter = FileAdapter('./src/security_policy.csv') casbin_enforcer.init_app(app, adapter) # casbin_enforcer = CasbinEnforcer(app, adapter) # casbin_enforcer = UpdatedCasbinEnforcer(adapter) @app.route("/") @casbin_enforcer.enforcer def index(): return jsonify({"hello": "world"}) from authz.resources.user import UserRegister, UserLogin, UserLogout api.add_resource(UserRegister, "/register") api.add_resource(UserLogin, "/login") api.add_resource(UserLogout, "/logout") # from authlogin.resources.security import NewGroup, GroupResource, UserGroup # api.add_resource(NewGroup, "/group") # api.add_resource(GroupResource, "/group/<int:_id>") # api.add_resource(UserGroup, "/usergroup/<int:_id>") # # api.add_resource(UserGroup, "/usergroup") from main.resources.store import NewStore, Store, StoreList api.add_resource(NewStore, "/store") api.add_resource(Store, "/store/<int:_id>") api.add_resource(StoreList, "/stores") return app
def configure_extensions(app): configure_assets(app) bcrypt.init_app(app) babel.init_app(app) cache.init_app(app) celery = Celery(app) mail.init_app(app) mongodb.init_app(app) sqldb.init_app(app) if app.debug: debugtoolbar = DebugToolbarExtension(app)
def init_extensions(app): db.init_app(app) db.app = app db.metadata.naming_convention = { "ix": 'ix_%(column_0_label)s', "uq": "uq_%(table_name)s_%(column_0_name)s", "ck": "ck_%(table_name)s_%(column_0_name)s", "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", "pk": "pk_%(table_name)s" } # set constraint naming convention to sensible default, per # http://docs.sqlalchemy.org/en/rel_0_9/core/constraints.html#configuring-constraint-naming-conventions assets.init_app(app) assets.app = app babel.init_app(app) cache.init_app(app) csrf.init_app(app) mail.init_app(app) login_manager.init_app(app) rq.init_app(app) app.rq = rq store.init_app(app) rest.init_app(app, flask_sqlalchemy_db=db, preprocessors=restless_preprocessors) rest.app = app limiter.init_app(app) for handler in app.logger.handlers: limiter.logger.addHandler(handler) # stable list of admin phone numbers, cached in memory to avoid db hit for each call # disable in testing if app.config.get('TESTING', False): app.ADMIN_PHONES_LIST = [] else: try: app.ADMIN_PHONES_LIST = filter(bool, [ str(u.phone.national_number) if u.phone else None for u in User.query.all() ]) except sqlalchemy.exc.SQLAlchemyError: # this may throw an error when creating the database from scratch pass if app.config.get('DEBUG'): from flask_debugtoolbar import DebugToolbarExtension DebugToolbarExtension(app) app.debug = True
def configure_extensions(app): # flask-mongoengine db.init_app(app) app.session_interface = MongoEngineSessionInterface(db) # flask-mail mail.init_app(app) # flask-babel babel.init_app(app) # Bcrypt for hashing passwords bcrypt.init_app(app) # the Gravatar service gravatar.init_app(app) # Markdown md.init_app(app) # Caching cache.init_app(app) # Debug Toolbar if app.debug: from flask_debugtoolbar import DebugToolbarExtension DebugToolbarExtension(app) @babel.localeselector def get_locale(): """ Get the current request locale. returns String """ if not hasattr(g, 'lang'): g.lang = 'en' accept_languages = app.config.get('ACCEPT_LANGUAGES') return g.lang or request.accept_languages.best_match(accept_languages) # flask-login login_manager.login_view = 'frontend.login' login_manager.refresh_view = 'frontend.reauth' @login_manager.user_loader def load_user(user_id): return User.objects(id=user_id).first() login_manager.setup_app(app)
def register_extensions(app): db.init_app(app) login_manager.init_app(app) csrf.init_app(app) csrf.exempt(api_v1) babel.init_app(app)
import os from glob import glob from random import choice from flask import Flask, render_template, jsonify, request from flask.ext.babel import gettext as _ from flask.ext.script import Manager from flask.ext.migrate import Migrate, MigrateCommand from extensions import db, babel from models import Question, Answer from commands import ParseAnswers app = Flask(__name__) app.config.from_object('config') babel.init_app(app) db.init_app(app) db.app = app migrate = Migrate(app, db) manager = Manager(app) manager.add_command('db', MigrateCommand) manager.add_command('parse_answers', ParseAnswers) def _get_random_background(): backgrounds_list = glob(os.path.join( app.config.get('BACKGROUND_IMAGES_DIRR'), '*.jpg')) background_path = choice(backgrounds_list) background_path = background_path.split('/')[-2:] return '/'.join(background_path) @app.errorhandler(404)
def configure_extensions(app): # flask-mongoengine db.init_app(app) app.session_interface = MongoEngineSessionInterface(db) # flask-mail mail.init_app(app) # flask-babel babel.init_app(app) # Bcrypt for hashing passwords bcrypt.init_app(app) # the Gravatar service gravatar.init_app(app) # Markdown md.init_app(app) # Caching cache.init_app(app) # Debug Toolbar if app.debug and app.config['DEBUG_TB_PROFILER_ENABLED']: from flask_debugtoolbar import DebugToolbarExtension DebugToolbarExtension(app) @babel.localeselector def get_locale(): """ Get the current request locale. returns String """ if not hasattr(g, 'lang'): g.lang = app.config.get('BABEL_DEFAULT_LOCALE') accept_languages = app.config.get('ACCEPT_LANGUAGES') # Try to guess the language from the user accept # header the browser transmits. We support ar/fr/en, # The best match wins. g.lang = session.get('language', None) or \ request.accept_languages.best_match(accept_languages) or \ g.lang if g.lang == 'ar': g.lang_dir = 'rtl' g.layout_dir_class = 'right-to-left' g.language_name = u'العربية' else: g.lang_dir = 'ltr' g.layout_dir_class = 'left-to-right' g.language_name = 'English' if g.lang == 'en' else u'Français' return g.lang # flask-login login_manager.login_view = 'frontend.login' login_manager.refresh_view = 'frontend.reauth' @login_manager.user_loader def load_user(user_id): return User.objects(id=user_id).first() login_manager.setup_app(app)