示例#1
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)
    db.init_app(app)
    bcrypt.init_app(app)

    app.register_blueprint(blog_blueprint)
    return app
示例#2
0
def register_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
示例#3
0
def register_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
示例#4
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)
    bcrypt.init_app(app)

    @app.route('/')
    def index():
        return redirect(url_for('blog.home'))

    app.register_blueprint(blog_blueprint)
    app.register_blueprint(main_blueprint)
    return app
示例#5
0
def create_app(object_name):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. project.config.ProdConfig
    """

    app = Flask(__name__)
    app.config.from_object(object_name)

    rest_api.add_resource(
        AuthApi,
        '/api/auth',
    )
    rest_api.add_resource(
        PostApi,
        '/api/post',
        '/api/post/<int:post_id>',
    )
    rest_api.init_app(app)

    db.init_app(app)
    mongo.init_app(app)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # Set the identity user object
        identity.user = current_user

        # Add the UserNeed to the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))

        # Add each role to the identity
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    app.register_blueprint(main_blueprint)
    app.register_blueprint(blog_blueprint)

    return app
示例#6
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)
    bcrypt.init_app(app)
    oid.init_app(app)

    @app.route('/')
    def index():
        return redirect(url_for('blog.home', page=1))

    app.register_blueprint(blog_blueprint)
    app.register_blueprint(main_blueprint)

    return app
示例#7
0
def create_app(object_name):
    """
    A flask application factory as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/
    :param   object_name: the python path of the config object
                        e.g. project.config.ProdConfig
    :return: app: The StudyBuddy application.
    """
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)
    bcrypt.init_app(app)

    app.register_blueprint(main_blueprint)
    app.register_blueprint(sb_blueprint)

    return app
示例#8
0
def create_app(object_name):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. project.config.ProdConfig

    """
    from webapp.models import db
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@localhost:5432/test5'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config.from_object('webapp.config.ProdConfig')
    #app.config.from_object('webapp.config.DevConfig')
    db.init_app(app)
    try:
        db.create_all()
    except Exception as e:
        print(e)
    bcrypt.init_app(app)
    oid.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)
    # db.create_all()

    app.register_blueprint(account_blueprint)
    app.register_blueprint(drivers_blueprint)
    app.register_blueprint(dvir_blueprint)
    app.register_blueprint(logs_blueprint)
    app.register_blueprint(trucks_blueprint)
    app.register_blueprint(elogstation_blueprint)
    # Create admin
    import flask_admin as admin1

    admin = admin1.Admin(app, 'Example: Auth', index_view=MyAdminIndexView(), base_template='my_master.html')
    # Add view
    admin.add_view(MyModelView(User, db.session))
    admin.add_view(MyModelView(Person, db.session))
    admin.add_view(MyModelView(companyuser, db.session))
    admin.add_view(MyModelView(company1, db.session))
    admin.add_view(MyModelView(ELD, db.session))
    return app
示例#9
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)

    bcrypt.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)

    rest_api = Api(app)
    rest_api.add_resource(PostApi,
            '/restapi/post',
            '/restapi/post/<int:post_id>',
            endpoint='restapi')

    app.register_blueprint(main_blueprint)
    app.register_blueprint(blog_blueprint)
    return app
示例#10
0
def create_app(objecrt_name):
    app = Flask(__name__)
    app.config.from_object(objecrt_name)

    db.init_app(app)
    bcrypt.init_app(app)
    oid.init_app(app)
    login_manager.init_app(app)
    principlals.init_app(app)

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # Set the identity user object
        identity.user = current_user

        # Add the UserNeed the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))

        # Add each role to the identity
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    # 根目录重定向到蓝图
    @app.route('/')
    def index():
        return redirect(url_for('blog.home'))

    app.add_url_rule('/',
                     view_func=GenericView.as_view('home',
                                                   template='home.html'))

    # 自定义错误404页面
    @app.errorhandler(404)
    def page_not_found(error):
        return render_template('page_not_found.html'), 404

    app.register_blueprint(blog_blueprint)
    app.register_blueprint(main_blueprint)
    return app
示例#11
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)
    celery.init_app(app)

    rest_api.add_resource(PostApi,
                          '/api/post',
                          '/api/post/<int:post_id>',
                          endpoint='api')
    rest_api.add_resource(AuthApi, '/api/auth')
    rest_api.init_app(app)

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        #set the identity user object
        identity.user = current_user

        #add the user need to the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))

        #add each role to the identity
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    # @app.route('/')
    # def index():
    # 	return redirect(url_for('blog.home'))

    app.register_blueprint(blog_blueprint)
    app.register_blueprint(main_blueprint)

    return app
示例#12
0
def create_app(object_name):
    """


    """
    from models import db
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///../databasetest.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config.from_object('config.ProdConfig')
    db.init_app(app)
    db.create_all()
    bcrypt.init_app(app)
    oid.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)
    celery.init_app(app)
    # Create admin
    import flask_admin as admin1
    admin = admin1.Admin(app, 'Elogstation', index_view=MyAdminIndexView())
    # Add view
    admin.add_view(MyModelView(User, db.session))
    return app
示例#13
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    #db.init_app(app)
    #event.listen(Reminder, 'after_insert', on_reminder_save)


    db.init_app(app)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)
    celery.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)
    admin.init_app(app)
    admin.add_view(CustomView(name='Custom'))

    models = [User,Role,Comment,Tag]
    for model in models:
        admin.add_view(CustomModelView(model,db.session,category='Models'))

    admin.add_view(
        PostView(
            Post, db.session, category='PostManager'
        )
    )
    admin.add_view(
        CustomFileAdmin(
            os.path.join(os.path.dirname(__file__), 'static'),
            '/static/',
            name='Static Files'
        )
    )

    rest_api.add_resource(
        AuthApi,
        '/api/auth',
    )
    rest_api.add_resource(
        PostApi,
        '/api/post',
        '/api/post/<int:post_id>',
    )
    rest_api.add_resource(
        CommentApi,
        '/api/comment',
        '/api/comment/<int:comment_id>',
        '/api/post/<int:post_id>/comment',
        '/api/post/<int:post_id>/comment/<int:comment_id>',
    )
    rest_api.init_app(app)



    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # Set the identity user object
        identity.user = current_user
        print "In __init_.py......:%s" %current_user

        # Add the UserNeed to the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))
            print UserNeed(current_user.id)

        # Add each role to the identity
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))
                print RoleNeed(role.name)



    app.register_blueprint(blog_blueprint)
    app.register_blueprint(main_blueprint)

    return app
示例#14
0
from models import db, Users

from controllers.blog import blog_blueprint
from controllers.user import user_blueprint
from controllers.login import login_blueprint
from webapp.extensions import bcrypt, rest_api
from .controllers.user import UserService
from .controllers.blog import BlogService

app = Flask(__name__)

app.config.from_object(DevConfig)
app.config['SECRET_KEY'] = 'super-secret'
db.init_app(app)
bcrypt.init_app(app)
jwt = JWT(app, authenticate, identity)

app.register_blueprint(user_blueprint)
app.register_blueprint(login_blueprint)
app.register_blueprint(blog_blueprint)

rest_api.add_resource(UserService, '/user')
rest_api.add_resource(BlogService, '/blog')
rest_api.init_app(app)

# @auth.verify_password
# def verify_password(username_or_token, password):
#     # first try to authenticate by token
#     user = User.verify_auth_token(username_or_token)
#     if not user:
示例#15
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)
    event.listen(Reminder, 'after_insert', on_reminder_save)
    bcrypt.init_app(app)
    oid.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)
    rest_api.add_resource(PostApi,
                          '/api/post',
                          '/api/post/<int:post_id>',
                          endpoint='api')
    rest_api.add_resource(AuthApi, '/api/auth', endpoint='auth')
    rest_api.init_app(app)
    celery.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)
    assets_env.init_app(app)
    assets_env.register("main_js", main_js)
    assets_env.register("main_css", main_css)
    admin.init_app(app)
    # admin.add_view(CustomView(name="Custom"))
    # models = [User, Role, Post, Comment, Tag, Reminder]
    # for model in models:
    #     if model is not Post:
    #         admin.add_view(
    #             CustomModelView(model, db.session, category="models")
    #         )
    #     else:
    #         admin.add_view(
    #             PostView(Post, db.session, category="models")
    #         )
    admin.add_view(CustomView(name='Custom'))
    admin.add_view(CustomModelView(User, db.session, category="Models"))
    admin.add_view(CustomModelView(Role, db.session, category="Models"))
    #
    # Need to use a special view for Posts to get the CKEditor functionality
    #
    admin.add_view(PostView(Post, db.session, category="Models"))
    admin.add_view(CustomModelView(Comment, db.session, category="Models"))
    admin.add_view(CustomModelView(Tag, db.session, category="Models"))
    admin.add_view(CustomModelView(Reminder, db.session, category="Models"))
    admin.add_view(
        CustomFileAdmin(os.path.join(os.path.dirname(__file__), 'static'),
                        '/static/',
                        name='Static Files'))
    mail.init_app(app)
    youtube_ext.init_app(app)
    #
    # The gzip extension and the debug toolbar can't both be running...
    #
    #    flask_gzip.init_app(app)

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        identity.user = current_user
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    #
    # Routes
    #
    @app.route('/')
    def index():
        return redirect(url_for('blog.home'))

    app.register_blueprint(blog_blueprint)
    app.register_blueprint(main_blueprint)

    return app