Exemple #1
0
def register_extensions(app):
    """Register Flask extensions."""

    db.init_app(app)
    ma.init_app(app)
    migrate.init_app(app, db, compare_server_default=True)
    from app.extensions import admin
    admin.init_app(app)

    # Import models
    return None
Exemple #2
0
def configure_admin(app):
    class AuthenticatedModelView(ModelView):
        def is_accessible(self):
            return login.current_user.is_authenticated() and login.current_user.role == ROLE_ADMIN

    admin.add_view(AuthenticatedModelView(User, db.session, endpoint='myuser'))
    admin.add_view(AuthenticatedModelView(Follow, db.session))
    admin.add_view(AuthenticatedModelView(SocialMediaAccount, db.session))
    admin.add_view(AuthenticatedModelView(FacebookAccount, db.session))
    admin.add_view(AuthenticatedModelView(TwitterAccount, db.session))
    admin.add_view(AuthenticatedModelView(Post, db.session))
    admin.add_view(AuthenticatedModelView(TwitterPost, db.session))
    admin.init_app(app)
Exemple #3
0
def configure_extensions(server):
    jwt.init_app(server)
    import app.admin.views
    admin.init_app(server)
    login_manager.init_app(server)
    sentry.init_app(server)
    babel = Babel(server)

    @babel.localeselector
    def get_locale():
        if request.args.get('lang'):
            session['lang'] = request.args.get('lang')
        return session.get('lang', 'en')
Exemple #4
0
def create_app(config_class=Config):
    app = Flask(__name__, template_folder='templates', static_folder='static')
    app.config.from_object(config_class)

    db.init_app(app)
    admin.init_app(app)
    login_manager.init_app(app)

    app.register_blueprint(main)
    app.register_blueprint(features)
    app.register_blueprint(errors)

    return app
Exemple #5
0
def register_extensions(app):
    """Register extensions with the Flask application."""
    travis.init_app(app)
    db.init_app(app)
    lm.init_app(app)
    mail.init_app(app)
    bcrypt.init_app(app)
    assets.init_app(app)
    babel.init_app(app)
    rq.init_app(app)
    migrate.init_app(app, db)
    limiter.init_app(app)
    admin.init_app(app)
Exemple #6
0
def configure_admin(app):
    class AuthenticatedModelView(ModelView):
        def is_accessible(self):
            return login.current_user.is_authenticated(
            ) and login.current_user.role == ROLE_ADMIN

    admin.add_view(AuthenticatedModelView(User, db.session, endpoint='myuser'))
    admin.add_view(AuthenticatedModelView(Follow, db.session))
    admin.add_view(AuthenticatedModelView(SocialMediaAccount, db.session))
    admin.add_view(AuthenticatedModelView(FacebookAccount, db.session))
    admin.add_view(AuthenticatedModelView(TwitterAccount, db.session))
    admin.add_view(AuthenticatedModelView(Post, db.session))
    admin.add_view(AuthenticatedModelView(TwitterPost, db.session))
    admin.init_app(app)
Exemple #7
0
def create_app(config_name='dev'):
    app = Flask(__name__)
    # sifn = show if none
    app.jinja_env.filters['sifn'] = lambda it: '无' if not it else it
    app.jinja_env.filters['with_site'] = lambda title: title + ' - pkyx'
    # 导入配置
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    # 初始化flask_admin
    admin.init_app(app)
    admin.add_view(FileView(os.path.join(os.path.dirname(__file__), 'static'), '/static/'))
    # 初始化MongoDB
    mongo.init_app(app)
    with app.app_context():
        mongo.db['items'].create_index('title', background=True)
    # 初始化Celery
    celery.init_app(app)
    # 初始化Flask-mail
    mail.init_app(app)
    # 初始化Flask-Login
    login_manager.init_app(app)
    login_manager.login_view = 'main.register'
    login_manager.login_message = '请先登录或注册'

    @login_manager.user_loader
    def load_user(user_id):
        user = None
        db_user = mongo.db.users.find_one({"_id": bson_obj_id(user_id)})
        if db_user is not None:
            user_id = db_user.pop('_id')
            user = User(user_id, extras=db_user)
        return user

    # @login_manager.unauthorized_handler
    # def unauthorized():
    #   pass


    from app.main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from app.users import users as users_blueprint
    app.register_blueprint(users_blueprint)

    from app.api import api as api_blueprint
    app.register_blueprint(api_blueprint)

    return app
Exemple #8
0
def configure_extensions(app):
    """configure flask extensions
    """
    cors.init_app(app, resources={r"/api/*": {"origins": "*"}})
    db.init_app(app)
    migrate.init_app(app, db)

    from app.models.user import User
    login_manager.init_app(app)

    @login_manager.user_loader
    def load_user(user_id):
        return User.query.filter(User.id == int(user_id)).first()

    from app.admin.views import ProtectedIndexView
    admin.init_app(app,
                   url='/admin',
                   index_view=ProtectedIndexView(name="Admin"))

    # Add the admin panel
    with app.app_context():
        pass
Exemple #9
0
from flask import Flask
from app.extensions import configuration
from app.extensions import commands
from app.extensions import database
from app.extensions import admin
from app.extensions import appearance
from app.extensions import auth
from app.blueprints import views
from app.blueprints import restapi

# Start app
app = Flask(__name__)

configuration.init_app(app)
commands.init_app(app)
database.init_app(app)
admin.init_app(app)
appearance.init_app(app)
auth.init_app(app)
views.init_app(app)
restapi.init_app(app)

Exemple #10
0
from .server import configure_server

""" Create the app """
app_instance = Flask(
    __name__,
    template_folder='../templates',
    static_folder="../static",
)

""" Bind config + security settings to app """
import app.core as app_core


""" Init + Bind extensions to app """
# Ordering is important.
admin.init_app(app_instance)
babel.init_app(app_instance)
bootstrap.init_app(app_instance)
db.init_app(app_instance)
serializer.init_app(app_instance)
mail.init_app(app_instance)
moment.init_app(app_instance)
health.init_app(app_instance, "/healthcheck")
register_app_cdn(app_instance)
assets.init_app(app_instance)   # Manage JavaScript bundles
templates.nav.init_app(app_instance)

# Inject db session into all models
BaseModel.set_session(db.session)

# Enable/Disable development extensions
Exemple #11
0
        return lang

    @babel.timezoneselector
    def get_timezone():
        user = getattr(g, 'user', None)
        if user is not None:
            return user.timezone
        return app.config['BABEL_DEFAULT_TIMEZONE']


app = Flask(__name__)
app.config.from_object(Config())
app.logger.debug('app created')

admin.init_app(app)
db.init_app(app)
init_i18n(app)
oid.init_app(app)

admin.add_view(BookmarkAdmin(Bookmark, db.session, endpoint='bookmarkadmin'))
admin.add_view(TagAdmin(Tag, db.session, endpoint='tagadmin'))
admin.add_view(UserAdmin(User, db.session, endpoint='useradmin'))

app.register_blueprint(links)


@app.before_first_request
def before_first_request():
    db.create_all()
Exemple #12
0
def register_admin(app, db):
    admin.init_app(app)
    admin.add_view(EventView(Event, db.session))
    admin.add_view(TeamView(Team, db.session))
    admin.add_view(PlayerView(Player, db.session))
    admin.add_view(CustomModelView(Task, db.session))
Exemple #13
0
def register_extensions(app):
    db.init_app(app)
    mail.init_app(app)
    admin.init_app(app)
    login_manager.init_app(app)