Python flask_admin 模块,helpers() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用flask_admin.helpers()

项目:qpd    作者:omaciel    | 项目源码 | 文件源码
def configure_admin(app, db):
    admin.init_app(app)
    # Admin pages
    admin.add_view(
        BaseView(OperatingSystem, db.session, endpoint='operatingsystems'))
    admin.add_view(BaseView(Project, db.session, endpoint='projects'))
    admin.add_view(ReleaseView(Release, db.session, endpoint='releases'))
    admin.add_view(TestRunView(TestRun, db.session, endpoint='testruns'))

    # security
    admin.add_view(BaseView(User, db.session, endpoint='users',
                            category='Auth'))
    admin.add_view(BaseView(Role, db.session, endpoint='roles',
                            category='Auth'))

    @app.security.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
            get_url=url_for
        )
项目:Canella-CMS    作者:mush42    | 项目源码 | 文件源码
def security_context_processor():
    return dict(
        admin_base_template=admin.base_template,
        admin_view=admin.index_view,
        h=admin_helpers,
        get_url=url_for,
        _gettext= gettext,
        _trans= gettext
    )
项目:contactista    作者:singingwolfboy    | 项目源码 | 文件源码
def admin_context():
    return dict(
        admin_base_template=admin.base_template,
        admin_view=admin.index_view,
        h=admin_helpers,
        get_url=url_for
    )
项目:dotadytt    作者:williamtse    | 项目源码 | 文件源码
def security_context_processor():
    return dict(
        admin_base_template=admin.base_template,
        admin_view=admin.index_view,
        h=admin_helpers,
        get_url=url_for
    )
项目:slim    作者:avalentino    | 项目源码 | 文件源码
def setup_components(app):
    # bootstrap
    Bootstrap(app)

    # sqlalchemy
    models.db.init_app(app)

    # security
    user_datastore = SQLAlchemyUserDatastore(models.db, models.User,
                                             models.Role)
    security = Security(app, user_datastore)

    # admin
    ModelView.page_size = app.config.get('SLIM_ITEMS_PER_PAGE', 5)
    admin.name = app.config.get('SLIM_APPNAME', 'SLiM')
    admin.init_app(app)

    # define a context processor for merging flask-admin's template context
    # into the flask-security views.
    @security.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
            get_url=url_for
        )

    # nav
    nav.init_app(app)

    # flask-uploads
    # patch_request_class(app, app.config['MAX_CONTENT_LENGTH'])
    request_uploader = UploadSet('requests',
                                 app.config['SLIM_REQUEST_EXTENSIONS'])
    configure_uploads(app, request_uploader)

    # components
    components = dict(
        user_datastore=user_datastore,
        security=security,
        request_uploader=request_uploader,
    )

    return components
项目:CourseScheduling-Web    作者:jennyzeng    | 项目源码 | 文件源码
def extensions(app):
    """
    Register 0 or more extensions (mutates the app passed in).

    :param app: Flask application instance
    :return: None
    """
    debug_toolbar.init_app(app)
    db.init_app(app)

    app.session_interface = mongoInterface
    # init login
    init_login(app)
    # Setup Flask-Security
    user_datastore = MongoEngineUserDatastore(db, User, Role)
    security = Security(app, user_datastore)
    # add admin view

    admin.init_app(app, index_view=HomeView())
    # admin.index_view =
    admin.add_view(CourseView(Course))
    admin.add_view(RequirementView(Requirement))
    admin.add_view(MajorView(Major))
    admin.add_view(QuarterView(Quarter))
    admin.add_view(UserView(User))
    admin.add_view(RoleView(Role))
    admin.add_view(FileUploadView(name='util', endpoint='util'))
    # define a context processor for merging flask-admin's template context into the
    # flask-security views.
    @security.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
            get_url=url_for
        )

    # Create a user to test with
    @app.before_first_request
    def create_user():
        user_datastore.find_or_create_role(name='superuser', description='Administrator')
        user_datastore.find_or_create_role(name='user', description='User')
        if not user_datastore.get_user('admin'):
            user_datastore.create_user(email='admin', password='admin')
        user_datastore.add_role_to_user('admin', 'superuser')

    return None