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


Python current_app.extensions方法代码示例

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


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

示例1: add_es_metadata_extensions

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def add_es_metadata_extensions(record_dict):
    """Add "extensions_X" fields to record_dict prior to Elasticsearch index.

    :param record_dict: dumped Record dict
    """
    rec_type = record_dict["$schema"].split("/")[-1].split("-")[0]
    metadata_extensions = getattr(
        current_app.extensions["invenio-app-ils"],
        "{}_metadata_extensions".format(rec_type)
    )

    for key, value in record_dict.get("extensions", {}).items():
        field_type = metadata_extensions.get_field_type(key, "elasticsearch")
        if not field_type:
            continue

        es_field = "extensions_{}s".format(field_type)

        if es_field not in record_dict:
            record_dict[es_field] = []

        record_dict[es_field].append({"key": key, "value": value}) 
开发者ID:inveniosoftware,项目名称:invenio-app-ils,代码行数:24,代码来源:metadata_extensions.py

示例2: send_mail

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def send_mail(
        self, template, subject, recipient, sender, body, html, user, **kwargs
    ):
        """Send an email via the Flask-Mail extension.

        :param template: the Template name. The message has already been rendered
            however this might be useful to differentiate why the email is being sent.
        :param subject: Email subject
        :param recipient: Email recipient
        :param sender: who to send email as (see :py:data:`SECURITY_EMAIL_SENDER`)
        :param body: the rendered body (text)
        :param html: the rendered body (html)
        :param user: the user model
        """

        from flask_mail import Message

        msg = Message(subject, sender=sender, recipients=[recipient])
        msg.body = body
        msg.html = html

        mail = current_app.extensions.get("mail")
        mail.send(msg) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:25,代码来源:mail_util.py

示例3: __init__

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if not self.next.data:
            self.next.data = request.args.get("next", "")
        self.remember.default = config_value("DEFAULT_REMEMBER_ME")
        if (
            current_app.extensions["security"].recoverable
            and not self.password.description
        ):
            html = Markup(
                '<a href="{url}">{message}</a>'.format(
                    url=url_for_security("forgot_password"),
                    message=get_message("FORGOT_PASSWORD")[0],
                )
            )
            self.password.description = html 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:18,代码来源:forms.py

示例4: init_app

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def init_app(self, app):
        for k, v in CONFIG_DEFAULTS.items():
            app.config.setdefault(k, v)
        app.config.setdefault('JWT_SECRET_KEY', app.config['SECRET_KEY'])

        auth_url_rule = app.config.get('JWT_AUTH_URL_RULE', None)

        if auth_url_rule:
            if self.auth_request_callback == _default_auth_request_handler:
                assert self.authentication_callback is not None, (
                    'an authentication_handler function must be defined when using the built in '
                    'authentication resource')

            auth_url_options = app.config.get('JWT_AUTH_URL_OPTIONS', {'methods': ['POST']})
            auth_url_options.setdefault('view_func', self.auth_request_callback)
            app.add_url_rule(auth_url_rule, **auth_url_options)

        app.errorhandler(JWTError)(self._jwt_error_callback)

        if not hasattr(app, 'extensions'):  # pragma: no cover
            app.extensions = {}

        app.extensions['jwt'] = self 
开发者ID:mattupstate,项目名称:flask-jwt,代码行数:25,代码来源:__init__.py

示例5: run_migrations_online

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = engine_from_config(config.get_section(config.config_ini_section),
                                prefix='sqlalchemy.',
                                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      **current_app.extensions['migrate'].configure_args)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close() 
开发者ID:sunscrapers,项目名称:flask-boilerplate,代码行数:23,代码来源:env.py

示例6: get_token_status

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def get_token_status(token):
    """Mimic flask_security.utils.get_token_status with some changes

    :param token: The token to decrypt
    :return: A tuple: (expired, invalid, user, data)
    """
    security = current_app.extensions['security']
    serializer = security.remember_token_serializer
    max_age = security.token_max_age

    user, data, error = None, None, None
    expired, invalid = False, False

    try:
        data = serializer.loads(token, max_age=max_age)
    except SignatureExpired:
        expired = True
    except (BadSignature, TypeError, ValueError) as e:
        invalid = True
        error = e

    if data:
        user = user_datastore.find_user(id=data[0])

    return expired, invalid, user, data, error 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:27,代码来源:user_handler.py

示例7: run_migrations_online

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    # this callback is used to prevent an auto-migration from being generated
    # when there are no changes to the schema
    # reference: http://alembic.readthedocs.org/en/latest/cookbook.html
    def process_revision_directives(context, revision, directives):
        if getattr(config.cmd_opts, 'autogenerate', False):
            script = directives[0]
            if script.upgrade_ops.is_empty():
                directives[:] = []
                logger.info('No changes in schema detected.')

    engine = engine_from_config(config.get_section(config.config_ini_section),
                                prefix='sqlalchemy.',
                                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      process_revision_directives=process_revision_directives,
                      **current_app.extensions['migrate'].configure_args)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:35,代码来源:env.py

示例8: run_migrations_online

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    # this callback is used to prevent an auto-migration from being generated
    # when there are no changes to the schema
    # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
    def process_revision_directives(context, revision, directives):
        if getattr(config.cmd_opts, 'autogenerate', False):
            script = directives[0]
            if script.upgrade_ops.is_empty():
                directives[:] = []
                logger.info('No changes in schema detected.')

    engine = engine_from_config(config.get_section(config.config_ini_section),
                                prefix='sqlalchemy.',
                                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      process_revision_directives=process_revision_directives,
                      **current_app.extensions['migrate'].configure_args)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close() 
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:35,代码来源:env.py

示例9: run_migrations_online

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    # this callback is used to prevent an auto-migration from being generated
    # when there are no changes to the schema
    # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
    def process_revision_directives(context, revision, directives):
        if getattr(config.cmd_opts, 'autogenerate', False):
            script = directives[0]
            if script.upgrade_ops.is_empty():
                directives[:] = []
                logger.info('No changes in schema detected.')

    connectable = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            process_revision_directives=process_revision_directives,
            **current_app.extensions['migrate'].configure_args
        )

        with context.begin_transaction():
            context.run_migrations() 
开发者ID:simple-login,项目名称:app,代码行数:36,代码来源:env.py

示例10: metadata

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def metadata(self):
        """
        Backwards compatibility, in old releases app.extensions['migrate']
        was set to db, and env.py accessed app.extensions['migrate'].metadata
        """
        return self.db.metadata 
开发者ID:jpush,项目名称:jbox,代码行数:8,代码来源:__init__.py

示例11: init_app

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def init_app(self, app, db=None, directory=None, **kwargs):
        self.db = db or self.db
        self.directory = directory or self.directory
        if not hasattr(app, 'extensions'):
            app.extensions = {}
        app.extensions['migrate'] = _MigrateConfig(self, self.db, **kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:8,代码来源:__init__.py

示例12: init

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def init(directory=None, multidb=False):
    """Generates a new migration"""
    if directory is None:
        directory = current_app.extensions['migrate'].directory
    config = Config()
    config.set_main_option('script_location', directory)
    config.config_file_name = os.path.join(directory, 'alembic.ini')
    config = current_app.extensions['migrate'].\
        migrate.call_configure_callbacks(config)
    if multidb:
        command.init(config, directory, 'flask-multidb')
    else:
        command.init(config, directory, 'flask') 
开发者ID:jpush,项目名称:jbox,代码行数:15,代码来源:__init__.py

示例13: revision

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def revision(directory=None, message=None, autogenerate=False, sql=False,
             head='head', splice=False, branch_label=None, version_path=None,
             rev_id=None):
    """Create a new revision file."""
    config = current_app.extensions['migrate'].migrate.get_config(directory)
    if alembic_version >= (0, 7, 0):
        command.revision(config, message, autogenerate=autogenerate, sql=sql,
                         head=head, splice=splice, branch_label=branch_label,
                         version_path=version_path, rev_id=rev_id)
    else:
        command.revision(config, message, autogenerate=autogenerate, sql=sql) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:__init__.py

示例14: migrate

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def migrate(directory=None, message=None, sql=False, head='head', splice=False,
            branch_label=None, version_path=None, rev_id=None):
    """Alias for 'revision --autogenerate'"""
    config = current_app.extensions['migrate'].migrate.get_config(
        directory, opts=['autogenerate'])
    if alembic_version >= (0, 7, 0):
        command.revision(config, message, autogenerate=True, sql=sql,
                         head=head, splice=splice, branch_label=branch_label,
                         version_path=version_path, rev_id=rev_id)
    else:
        command.revision(config, message, autogenerate=True, sql=sql) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:__init__.py

示例15: merge

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import extensions [as 别名]
def merge(directory=None, revisions='', message=None, branch_label=None,
          rev_id=None):
    """Merge two revisions together.  Creates a new migration file"""
    if alembic_version >= (0, 7, 0):
        config = current_app.extensions['migrate'].migrate.get_config(
            directory)
        command.merge(config, revisions, message=message,
                      branch_label=branch_label, rev_id=rev_id)
    else:
        raise RuntimeError('Alembic 0.7.0 or greater is required') 
开发者ID:jpush,项目名称:jbox,代码行数:12,代码来源:__init__.py


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