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


Python current_app._get_current_object方法代码示例

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


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

示例1: post

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def post(self, pid, record, **kwargs):
        """Send a signal to count record view for the record stats."""
        data = request.get_json()
        event_name = data.get("event")
        if event_name == "record-view":
            record_viewed.send(
                current_app._get_current_object(), pid=pid, record=record,
            )
            return self.make_response(pid, record, 202)
        elif event_name == "file-download":
            if "key" not in data:
                abort(406, "File key is required")
            if "bucket_id" not in record:
                abort(406, "Record has no bucket")
            obj = ObjectVersion.get(record["bucket_id"], data["key"])
            file_downloaded.send(
                current_app._get_current_object(), obj=obj, record=record
            )
            return self.make_response(pid, record, 202)
        return StatsError(
            description="Invalid stats event request: {}".format(event_name)
        ) 
开发者ID:inveniosoftware,项目名称:invenio-app-ils,代码行数:24,代码来源:views.py

示例2: _check_token

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def _check_token():
    # N.B. this isn't great Flask-Login 0.5.0 made this protected
    # Issue https://github.com/maxcountryman/flask-login/issues/471
    # was filed to restore public access. We want to call this via
    # login_manager in case someone has overridden the login_manager which we
    # allow.
    if hasattr(_security.login_manager, "request_callback"):
        # Pre 0.5.0
        user = _security.login_manager.request_callback(request)
    else:
        user = _security.login_manager._request_callback(request)

    if user and user.is_authenticated:
        app = current_app._get_current_object()
        _request_ctx_stack.top.user = user
        identity_changed.send(app, identity=Identity(user.fs_uniquifier))
        return True

    return False 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:21,代码来源:decorators.py

示例3: send_confirmation_instructions

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def send_confirmation_instructions(user):
    """Sends the confirmation instructions email for the specified user.

    :param user: The user to send the instructions to
    """

    confirmation_link, token = generate_confirmation_link(user)

    send_mail(
        config_value("EMAIL_SUBJECT_CONFIRM"),
        user.email,
        "confirmation_instructions",
        user=user,
        confirmation_link=confirmation_link,
    )

    confirm_instructions_sent.send(app._get_current_object(), user=user, token=token) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:19,代码来源:confirmable.py

示例4: complete_two_factor_process

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def complete_two_factor_process(
    user, primary_method, totp_secret, is_changing, remember_login=None
):
    """clean session according to process (login or changing two-factor method)
     and perform action accordingly
    """

    _datastore.tf_set(user, primary_method, totp_secret=totp_secret)

    # if we are changing two-factor method
    if is_changing:
        completion_message = "TWO_FACTOR_CHANGE_METHOD_SUCCESSFUL"
        tf_profile_changed.send(
            app._get_current_object(), user=user, method=primary_method
        )
    # if we are logging in for the first time
    else:
        completion_message = "TWO_FACTOR_LOGIN_SUCCESSFUL"
        tf_code_confirmed.send(
            app._get_current_object(), user=user, method=primary_method
        )
        login_user(user, remember=remember_login)
    tf_clean_session()
    return completion_message 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:26,代码来源:twofactor.py

示例5: send_reset_password_instructions

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def send_reset_password_instructions(user):
    """Sends the reset password instructions email for the specified user.

    :param user: The user to send the instructions to
    """
    token = generate_reset_password_token(user)
    reset_link = url_for_security("reset_password", token=token, _external=True)

    if config_value("SEND_PASSWORD_RESET_EMAIL"):
        send_mail(
            config_value("EMAIL_SUBJECT_PASSWORD_RESET"),
            user.email,
            "reset_instructions",
            user=user,
            reset_link=reset_link,
        )

    reset_password_instructions_sent.send(
        app._get_current_object(), user=user, token=token
    ) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:22,代码来源:recoverable.py

示例6: send_login_instructions

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def send_login_instructions(user):
    """Sends the login instructions email for the specified user.

    :param user: The user to send the instructions to
    """
    token = generate_login_token(user)
    login_link = url_for_security("token_login", token=token, _external=True)

    send_mail(
        config_value("EMAIL_SUBJECT_PASSWORDLESS"),
        user.email,
        "login_instructions",
        user=user,
        login_link=login_link,
    )

    login_instructions_sent.send(
        app._get_current_object(), user=user, login_token=token
    ) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:21,代码来源:passwordless.py

示例7: add_server

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def add_server(self, hostname, port, use_ssl, tls_ctx=None, app=None):
        """
        Add an additional server to the server pool and return the
        freshly created server.

        Args:
            hostname (str): Hostname of the server
            port (int): Port of the server
            use_ssl (bool): True if SSL is to be used when connecting.
            tls_ctx (ldap3.Tls): An optional TLS context object to use
                when connecting.
            app (flask.Flask): The app on which to add the server. If not
                given, ``flask.current_app`` is used.

        Returns:
            ldap3.Server: The freshly created server object.
        """
        if app is None:
            app = current_app._get_current_object()
        if not use_ssl and tls_ctx:
            raise ValueError("Cannot specify a TLS context and not use SSL!")
        server = ldap3.Server(hostname, port=port, use_ssl=use_ssl, tls=tls_ctx)
        app.ldap3_login_manager_server_pool.add(server)
        return server 
开发者ID:nickw444,项目名称:flask-ldap3-login,代码行数:26,代码来源:__init__.py

示例8: handle

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def handle(data):
    ret = []

    def timeout_handle():
        return '\n'.join([r[0] for r in ret]), [r[1] for r in ret]

    @timeout(15, default=timeout_handle)
    def _handle(data, app):
        message = data['message']
        if not isinstance(message, unicode):
            message = message.decode('utf-8')
        msg = message.split()
        if len(msg) == 1 or (len(msg) == 2 and u'私聊' in msg[1]):
            city = 'beijing'
        else:
            city = to_pinyin(msg[1])
        if u'将' in message:
            fn = get_later_movie_info
        else:
            fn = get_current_movie_info
        for r in fn(city, app):
            ret.append(r)
        return '\n'.join([r[0] for r in ret]), [r[1] for r in ret]
    app = current_app._get_current_object()
    return _handle(data, app) 
开发者ID:python-cn,项目名称:slack_bot,代码行数:27,代码来源:movie.py

示例9: change_password

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def change_password(self, user, password, send_email=None):
        """
        Service method to change a user's password.

        Sends signal `password_changed`.

        :param user: The :class:`User`'s password to change.
        :param password: The new password.
        :param send_email: Whether or not to override the config option
                           ``SECURITY_SEND_PASSWORD_CHANGED_EMAIL`` and force
                           either sending or not sending an email.
        """
        user.password = password
        self.user_manager.save(user)
        if send_email or (app.config.SECURITY_SEND_PASSWORD_CHANGED_EMAIL
                          and send_email is None):
            self.send_mail(
                _('flask_unchained.bundles.security:email_subject.password_changed_notice'),
                to=user.email,
                template='security/email/password_changed_notice.html',
                user=user)
        password_changed.send(app._get_current_object(), user=user) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:24,代码来源:security_service.py

示例10: reset_password

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def reset_password(self, user, password):
        """
        Service method to reset a user's password. The same as :meth:`change_password`
        except we this method sends a different notification email.

        Sends signal `password_reset`.

        :param user:
        :param password:
        :return:
        """
        user.password = password
        self.user_manager.save(user)
        if app.config.SECURITY_SEND_PASSWORD_RESET_NOTICE_EMAIL:
            self.send_mail(
                _('flask_unchained.bundles.security:email_subject.password_reset_notice'),
                to=user.email,
                template='security/email/password_reset_notice.html',
                user=user)
        password_reset.send(app._get_current_object(), user=user) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:22,代码来源:security_service.py

示例11: send_reset_password_instructions

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def send_reset_password_instructions(self, user):
        """
        Sends the reset password instructions email for the specified user.

        Sends signal `reset_password_instructions_sent`.

        :param user: The user to send the instructions to.
        """
        token = self.security_utils_service.generate_reset_password_token(user)
        reset_link = url_for('security_controller.reset_password',
                             token=token, _external=True)
        self.send_mail(
            _('flask_unchained.bundles.security:email_subject.reset_password_instructions'),
            to=user.email,
            template='security/email/reset_password_instructions.html',
            user=user,
            reset_link=reset_link)
        reset_password_instructions_sent.send(app._get_current_object(),
                                              user=user, token=token) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:21,代码来源:security_service.py

示例12: get_app

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def get_app(self, reference_app=None):
        """Helper method that implements the logic to look up an
        application."""

        if reference_app is not None:
            return reference_app

        if current_app:
            return current_app._get_current_object()

        if self.app is not None:
            return self.app

        raise RuntimeError(
            'No application found. Either work inside a view function or push'
            ' an application context. See'
            ' http://flask-sqlalchemy.pocoo.org/contexts/.'
        ) 
开发者ID:yfauser,项目名称:planespotter,代码行数:20,代码来源:__init__.py

示例13: cron

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def cron(testing=False):
    """Script to run from cron for Sampleplatform."""
    from mod_ci.controllers import start_platforms, kvm_processor, TestPlatform
    from flask import current_app
    from run import config, log
    from database import create_session
    from github import GitHub

    log.info('Run the cron for kicking off CI platform(s).')
    # Create session
    db = create_session(config['DATABASE_URI'])
    gh = GitHub(access_token=config['GITHUB_TOKEN'])
    repository = gh.repos(config['GITHUB_OWNER'])(config['GITHUB_REPOSITORY'])

    if testing is True:
        kvm_processor(current_app._get_current_object(), db, config.get('KVM_LINUX_NAME', ''), TestPlatform.linux,
                      repository, None)
    else:
        start_platforms(db, repository) 
开发者ID:CCExtractor,项目名称:sample-platform,代码行数:21,代码来源:cron.py

示例14: start_platforms

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def start_platforms(db, repository, delay=None, platform=None) -> None:
    """
    Start new test on both platforms in parallel.

    We use multiprocessing module which bypasses Python GIL to make use of multiple cores of the processor.
    """
    from run import config, log, app

    with app.app_context():
        from flask import current_app
        if platform is None or platform == TestPlatform.linux:
            linux_kvm_name = config.get('KVM_LINUX_NAME', '')
            log.info('Define process to run Linux VM')
            linux_process = Process(target=kvm_processor, args=(current_app._get_current_object(), db, linux_kvm_name,
                                                                TestPlatform.linux, repository, delay,))
            linux_process.start()
            log.info('Linux VM process kicked off')

        if platform is None or platform == TestPlatform.windows:
            win_kvm_name = config.get('KVM_WINDOWS_NAME', '')
            log.info('Define process to run Windows VM')
            windows_process = Process(target=kvm_processor, args=(current_app._get_current_object(), db, win_kvm_name,
                                                                  TestPlatform.windows, repository, delay,))
            windows_process.start()
            log.info('Windows VM process kicked off') 
开发者ID:CCExtractor,项目名称:sample-platform,代码行数:27,代码来源:controllers.py

示例15: post

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import _get_current_object [as 别名]
def post(self):
        if request.form.get('login_github'):
            session['oauth_callback_type'] = 'login'
            return github_auth.github_auth()
            # return 'login_github'

        form = forms.LoginForm(obj=request.form)
        if form.validate():
            try:
                user = models.User.objects.get(username=form.username.data)
            except models.User.DoesNotExist:
                user = None

            if user and user.verify_password(form.password.data):
                login_user(user, form.remember_me.data)
                user.last_login = datetime.datetime.now
                user.save()
                identity_changed.send(current_app._get_current_object(), identity=Identity(user.username))
                return redirect(request.args.get('next') or url_for('main.index'))
            flash('Invalid username or password', 'danger')
        return self.get(form=form) 
开发者ID:GitMarkTeam,项目名称:gitmark,代码行数:23,代码来源:views.py


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