当前位置: 首页>>代码示例>>Python>>正文


Python flask_mongoengine.MongoEngine方法代码示例

本文整理汇总了Python中flask_mongoengine.MongoEngine方法的典型用法代码示例。如果您正苦于以下问题:Python flask_mongoengine.MongoEngine方法的具体用法?Python flask_mongoengine.MongoEngine怎么用?Python flask_mongoengine.MongoEngine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_mongoengine的用法示例。


在下文中一共展示了flask_mongoengine.MongoEngine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_app

# 需要导入模块: import flask_mongoengine [as 别名]
# 或者: from flask_mongoengine import MongoEngine [as 别名]
def init_app(app):
    admin = flask_admin.Admin(app=app, name='ProxyPool Admin', base_template="admin/master_base.html", index_view=ProxyPoolAdminIndexView(), template_mode='bootstrap3')
    admin.add_view(ProxyView(ProxyModel))
    admin.add_view(SettingView(SettingModel))
    # admin.add_view(ProxyPoolView(ProxyPoolModel))
    admin.add_view(FetcherView(FetcherModel))

    db = MongoEngine()
    db.init_app(app)

    user_datastore = MongoEngineUserDatastore(db, User, Role)
    init_security(user_datastore, app, admin)

    init_base_data(user_datastore, app) 
开发者ID:ozhiwei,项目名称:SmartProxyPool,代码行数:16,代码来源:admin.py

示例2: mongoengine_setup

# 需要导入模块: import flask_mongoengine [as 别名]
# 或者: from flask_mongoengine import MongoEngine [as 别名]
def mongoengine_setup(request, app, tmpdir, realdburl):
    from flask_mongoengine import MongoEngine
    from mongoengine.fields import (
        BooleanField,
        DateTimeField,
        IntField,
        ListField,
        ReferenceField,
        StringField,
    )

    db_name = "flask_security_test_%s" % str(time.time()).replace(".", "_")
    app.config["MONGODB_SETTINGS"] = {
        "db": db_name,
        "host": "mongomock://localhost",
        "port": 27017,
        "alias": db_name,
    }

    db = MongoEngine(app)

    class Role(db.Document, RoleMixin):
        name = StringField(required=True, unique=True, max_length=80)
        description = StringField(max_length=255)
        permissions = StringField(max_length=255)
        meta = {"db_alias": db_name}

    class User(db.Document, UserMixin):
        email = StringField(unique=True, max_length=255)
        fs_uniquifier = StringField(unique=True, max_length=64, required=True)
        username = StringField(unique=True, required=False, sparse=True, max_length=255)
        password = StringField(required=False, max_length=255)
        security_number = IntField(unique=True, required=False, sparse=True)
        last_login_at = DateTimeField()
        current_login_at = DateTimeField()
        tf_primary_method = StringField(max_length=255)
        tf_totp_secret = StringField(max_length=255)
        tf_phone_number = StringField(max_length=255)
        us_totp_secrets = StringField()
        us_phone_number = StringField(max_length=255)
        last_login_ip = StringField(max_length=100)
        current_login_ip = StringField(max_length=100)
        login_count = IntField()
        active = BooleanField(default=True)
        confirmed_at = DateTimeField()
        roles = ListField(ReferenceField(Role), default=[])
        meta = {"db_alias": db_name}

    def tear_down():
        with app.app_context():
            User.drop_collection()
            Role.drop_collection()
            db.connection.drop_database(db_name)

    request.addfinalizer(tear_down)

    return MongoEngineUserDatastore(db, User, Role) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:59,代码来源:conftest.py

示例3: init_app

# 需要导入模块: import flask_mongoengine [as 别名]
# 或者: from flask_mongoengine import MongoEngine [as 别名]
def init_app(name):
    """
    :param name: application alias
    :type name: str

    :return: Bootstrapped cached application instance
    :rtype: flask.Flask
    """
    key = 'app'

    if not hasattr(init_app, key):
        app = flask.Flask(name)

        app.config.from_object('vulyk.settings')

        try:
            app.config.from_object('local_settings')
        except ImportError:
            pass

        app.template_folder = app.config.get('TEMPLATES_FOLDER', 'templates')
        app.static_folder = app.config.get('STATIC_FOLDER', 'static')

        _logging.init_logger(app=app)
        app.logger.info('STARTING.')

        db = MongoEngine(app)

        app.logger.debug('Database is available at %s:%s',
                         app.config['MONGODB_SETTINGS'].get('HOST',
                                                            'localhost'),
                         app.config['MONGODB_SETTINGS'].get('PORT', 27017))

        _assets.init(app)
        _social_login.init_social_login(app, db)

        if app.config.get('ENABLE_ADMIN', False):
            from . import _admin
            app.admin = _admin.init_admin(app)

        _blueprints.init_blueprints(app)

        setattr(init_app, key, app)

        app.logger.info('Vulyk bootstrapping complete.')

    return getattr(init_app, key)
# endregion Init 
开发者ID:mrgambal,项目名称:vulyk,代码行数:50,代码来源:__init__.py


注:本文中的flask_mongoengine.MongoEngine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。