本文整理匯總了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)
)
示例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
示例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)
示例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
示例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
)
示例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
)
示例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
示例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)
示例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)
示例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)
示例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)
示例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/.'
)
示例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)
示例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')
示例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)