當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。