本文整理汇总了Python中flask.flash方法的典型用法代码示例。如果您正苦于以下问题:Python flask.flash方法的具体用法?Python flask.flash怎么用?Python flask.flash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块flask的用法示例。
在下文中一共展示了flask.flash方法的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: skip
点赞 6
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def skip(self):
if g.user is None:
self.logger.info('[%s][%s] anonymous skip', g.user, self.name)
return redirect(url_for(self.name + '.index'))
g.user.lock()
if not self.can_skip():
g.user.unlock()
self.logger.warning('[%s][%s] skip() but can\'t skip', g.user, self.name)
return render_template('forbidden.html'), 403
g.user.setstate(self, 'skipped')
g.user.commit()
self.logger.info('[%s][%s] skipped', g.user, self.name)
flash(u"Te has saltado el nivel %d" % self.number)
try:
next = self.route_.levels[self.routeidx+1]
return redirect(url_for(next.name + '.index'))
except IndexError:
alldone = all([l.state() == 'solved' for r in routes for l in r.levels])
self.logger.info('[%s][%s] last level (alldone=%r)', g.user, self.name, alldone)
return render_template('alldone.html', alldone=alldone, level=self)
开发者ID:marcan,项目名称:hackit,代码行数:25,
示例2: is_admin_sess_timedout
点赞 6
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def is_admin_sess_timedout(function):
"""
Decorator that checks if the admin session has timeout.
If not true redirect to the login page
"""
@wraps(function)
def check_session_timeout(*args, **kwargs):
if admin_session_timedout():
if flask.request.method == "POST":
flask.flash("Action canceled, try it again", "error")
return flask.redirect(
flask.url_for("auth_login", next=flask.request.url)
)
return function(*args, **kwargs)
return check_session_timeout
开发者ID:Pagure,项目名称:pagure,代码行数:19,
示例3: auth_logout
点赞 6
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def auth_logout(): # pragma: no cover
""" Method to log out from the application. """
return_point = flask.url_for("ui_ns.index")
if "next" in flask.request.args:
if pagure.utils.is_safe_url(flask.request.args["next"]):
return_point = flask.request.args["next"]
if not pagure.utils.authenticated():
return flask.redirect(return_point)
logout()
flask.flash("You have been logged out")
flask.session["_justloggedout"] = True
return flask.redirect(return_point)
# pylint: disable=unused-argument
开发者ID:Pagure,项目名称:pagure,代码行数:19,
示例4: confirm_user
点赞 6
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def confirm_user(token):
""" Confirm a user account.
"""
user_obj = pagure.lib.query.search_user(flask.g.session, token=token)
if not user_obj:
flask.flash("No user associated with this token.", "error")
else:
user_obj.token = None
flask.g.session.add(user_obj)
try:
flask.g.session.commit()
flask.flash("Email confirmed, account activated")
return flask.redirect(flask.url_for("auth_login"))
except SQLAlchemyError as err: # pragma: no cover
flask.flash(
"Could not set the account as active in the db, "
"please report this error to an admin",
"error",
)
_log.exception(err)
return flask.redirect(flask.url_for("ui_ns.index"))
开发者ID:Pagure,项目名称:pagure,代码行数:25,
示例5: feedback
点赞 6
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def feedback():
if not config.CONFIG_DB.feedback_email:
return flask.abort(418)
form = FeedbackForm(obj=auth.current_user_db())
if not config.CONFIG_DB.has_anonymous_recaptcha or auth.is_logged_in():
del form.recaptcha
if form.validate_on_submit():
body = '%s\n\n%s' % (form.message.data, form.email.data)
kwargs = {'reply_to': form.email.data} if form.email.data else {}
task.send_mail_notification('%s...' % body[:48].strip(), body, **kwargs)
flask.flash('Thank you for your feedback!', category='success')
return flask.redirect(flask.url_for('welcome'))
return flask.render_template(
'feedback.html',
title='Feedback',
html_class='feedback',
form=form,
)
开发者ID:lipis,项目名称:github-stats,代码行数:22,
示例6: oauth_callback
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def oauth_callback():
"""OAuth handshake callback."""
if 'request_token' not in flask.session:
flask.flash(u'OAuth callback failed. Are cookies disabled?')
return flask.redirect(flask.url_for('index'))
consumer_token = mwoauth.ConsumerToken(
app.config['CONSUMER_KEY'], app.config['CONSUMER_SECRET'])
try:
access_token = mwoauth.complete(
app.config['OAUTH_MWURI'],
consumer_token,
mwoauth.RequestToken(**flask.session['request_token']),
flask.request.query_string)
identity = mwoauth.identify(
app.config['OAUTH_MWURI'], consumer_token, access_token)
except Exception as e:
app.logger.exception('OAuth authentication failed')
else:
flask.session['access_token'] = dict(zip(
access_token._fields, access_token))
print(' ACCESS_TOKEN')
print(access_token)
flask.session['username'] = identity['username']
next_url = flask.request.args.get('next_url') or flask.url_for('get_random_edit')
return flask.redirect(next_url)
开发者ID:dissemin,项目名称:oabot,代码行数:32,
示例7: index
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def index():
# return flask.send_from_directory('./static/', 'index.html')
flask.flash(str((fan.speed, fan.brightness)))
return flask.render_template("index.html")
# Light Functions
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:9,
示例8: toggle_light
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def toggle_light():
fan.light_toggle()
flask.flash("Toggling Light")
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例9: light_off
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def light_off():
fan.light_powered_on = False
flask.flash("Turning Light Off")
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例10: light_on
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def light_on():
fan.light_powered_on = True
flask.flash("Turning light On")
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例11: light_level
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def light_level(level):
fan.brightness = int(level)
flask.flash("Set light level to {}".format(level))
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例12: dec_light
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def dec_light():
fan.dec_brightness()
flask.flash("Decreased Light Level")
return flask.redirect(flask.url_for("index"))
# Fan Functions
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:9,
示例13: inc_speed
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def inc_speed():
fan.inc_speed()
flask.flash("Increased Fan Speed")
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例14: dec_speed
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def dec_speed():
fan.dec_speed()
flask.flash("Decreased Fan Speed")
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例15: set_speed
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def set_speed(speed):
fan.speed = int(speed)
flask.flash("Set fan speed to {}".format(speed))
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例16: fan_toggle
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def fan_toggle():
fan.fan_toggle()
flask.flash("Toggling Fan")
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例17: fan_on
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def fan_on():
fan.fan_powered_on = True
flask.flash("Turning Fan On")
return flask.redirect(flask.url_for("index"))
开发者ID:TomFaulkner,项目名称:SenseMe,代码行数:6,
示例18: add_machine
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def add_machine():
# Check that we have an active user.
user = current_app.get_active_user()
if user is None:
abort(401)
# Check that the user has authority to access the lab.
if not user.has_lab_access():
abort(401)
# If this isn't a post request, return the template.
if request.method != 'POST':
return render_template("add_machine.html", error=None)
# Validate the entry data.
id = request.form['id']
hostname = request.form['hostname']
if id in current_app.config.data.machines:
return render_template("add_machine.html",
error='machine "%s" already exists' % id)
if hostname in set(m.hostname
for m in current_app.config.data.machines.values()):
return render_template("add_machine.html",
error='hostname "%s" already used' % hostname)
# Add the machine record.
machine = llvmlab.machine.Machine(id, hostname, user.id)
current_app.config.data.machines[machine.id] = machine
flask.flash('Added machine "%s"!' % machine.id)
# Save the application data.
current_app.save_data()
flask.flash('Saved data!')
return redirect(url_for("admin"))
开发者ID:llvm,项目名称:llvm-zorg,代码行数:37,
示例19: login
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def login():
# If this isn't a post request, return the login template.
if request.method != 'POST':
return render_template("login.html", error=None)
# Authenticate the user.
username = request.form['username']
if not current_app.authenticate_login(username, request.form['password']):
return render_template("login.html",
error="Invalid login")
# Log the user in.
session['logged_in'] = True
session['active_user'] = username
flask.flash('You were logged in as "%s"!' % username)
return redirect(url_for("index"))
开发者ID:llvm,项目名称:llvm-zorg,代码行数:18,
示例20: logout
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def logout():
session.pop('logged_in', None)
session.pop('active_user', None)
flask.flash('You were logged out!')
return redirect(url_for("index"))
开发者ID:llvm,项目名称:llvm-zorg,代码行数:7,
示例21: schedule_sync_mirror
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def schedule_sync_mirror(mirror_id: int):
# Check if mirror exists or throw 404
found_mirror = PushMirror.query.filter_by(id=mirror_id, user=current_user).first_or_404()
if not found_mirror.project_id:
flask.flash('Project mirror is not created, cannot be synced', 'danger')
return flask.redirect(flask.url_for('push_mirror.index.get_mirror'))
task = sync_push_mirror.delay(mirror_id)
log_task_pending(task, found_mirror, sync_push_mirror, InvokedByEnum.MANUAL)
flask.flash('Sync has been started with UUID: {}'.format(task.id), 'success')
return flask.redirect(flask.url_for('push_mirror.index.get_mirror'))
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:13,
示例22: schedule_delete_mirror
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def schedule_delete_mirror(mirror_id: int):
mirror_detail = PushMirror.query.filter_by(id=mirror_id, user=current_user).first_or_404()
mirror_detail.is_deleted = True
db.session.add(mirror_detail)
db.session.commit()
delete_push_mirror.delay(mirror_detail.id)
flask.flash('Push mirror was deleted successfully.', 'success')
return flask.redirect(flask.url_for('push_mirror.index.get_mirror'))
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:13,
示例23: new_fingerprint
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def new_fingerprint():
form = NewForm(
flask.request.form
)
if flask.request.method == 'POST' and form.validate():
flask.flash('New fingerprint was added.', 'success')
return flask.redirect(flask.url_for('fingerprint.index.get_fingerprint'))
return flask.render_template('fingerprint.index.new.html', form=form)
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:11,
示例24: get_new_rsa_key
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def get_new_rsa_key():
current_user.is_rsa_pair_set = False
current_user.gitlab_deploy_key_id = None
db.session.add(current_user)
db.session.commit()
create_rsa_pair.delay(current_user.id)
flask.flash('New RSA pair key has been requested!', 'success')
return flask.redirect(flask.url_for('home.index.get_home'))
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:12,
示例25: schedule_sync_mirror
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def schedule_sync_mirror(mirror_id: int):
# Check if mirror exists or throw 404
found_mirror = PullMirror.query.filter_by(id=mirror_id, user=current_user).first_or_404()
if not found_mirror.project_id:
flask.flash('Project mirror is not created, cannot be synced', 'danger')
return flask.redirect(flask.url_for('pull_mirror.index.get_mirror'))
task = sync_pull_mirror.delay(mirror_id)
log_task_pending(task, found_mirror, sync_pull_mirror, InvokedByEnum.MANUAL)
flask.flash('Sync has been started with UUID: {}'.format(task.id), 'success')
return flask.redirect(flask.url_for('pull_mirror.index.get_mirror'))
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:13,
示例26: schedule_delete_mirror
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def schedule_delete_mirror(mirror_id: int):
mirror_detail = PullMirror.query.filter_by(id=mirror_id, user=current_user).first_or_404()
mirror_detail.is_deleted = True
db.session.add(mirror_detail)
db.session.commit()
delete_pull_mirror.delay(mirror_detail.id)
flask.flash('Pull mirror was deleted successfully.', 'success')
return flask.redirect(flask.url_for('pull_mirror.index.get_mirror'))
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:13,
示例27: login_required
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def login_required(function):
""" Flask decorator to retrict access to logged in user.
If the auth system is ``fas`` it will also require that the user sign
the FPCA.
"""
@wraps(function)
def decorated_function(*args, **kwargs):
""" Decorated function, actually does the work. """
auth_method = pagure_config.get("PAGURE_AUTH", None)
if flask.session.get("_justloggedout", False):
return flask.redirect(flask.url_for("ui_ns.index"))
elif not authenticated():
return flask.redirect(
flask.url_for("auth_login", next=flask.request.url)
)
elif auth_method == "fas" and not flask.g.fas_user.cla_done:
flask.session["_requires_fpca"] = True
flask.flash(
flask.Markup(
'You must sign the FPCA (Fedora Project '
"Contributor Agreement) to use pagure"
),
"errors",
)
return flask.redirect(flask.url_for("ui_ns.index"))
return function(*args, **kwargs)
return decorated_function
开发者ID:Pagure,项目名称:pagure,代码行数:32,
示例28: get_task_redirect_url
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def get_task_redirect_url(task, prev):
if not task.ready():
return flask.url_for("ui_ns.wait_task", taskid=task.id, prev=prev)
result = task.get(timeout=0, propagate=False)
if task.failed():
flask.flash("Your task failed: %s" % result)
task.forget()
return prev
if isinstance(result, dict):
endpoint = result.pop("endpoint")
task.forget()
return flask.url_for(endpoint, **result)
else:
task.forget()
flask.abort(418)
开发者ID:Pagure,项目名称:pagure,代码行数:17,
示例29: update_user_settings
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def update_user_settings():
""" Update the user's settings set in the settings page.
"""
if admin_session_timedout():
if flask.request.method == "POST":
flask.flash("Action canceled, try it again", "error")
return flask.redirect(
flask.url_for("auth_login", next=flask.request.url)
)
user = _get_user(username=flask.g.fas_user.username)
form = pagure.forms.ConfirmationForm()
if form.validate_on_submit():
settings = {}
for key in flask.request.form:
if key == "csrf_token":
continue
settings[key] = flask.request.form[key]
try:
message = pagure.lib.query.update_user_settings(
flask.g.session, settings=settings, user=user.username
)
flask.g.session.commit()
flask.flash(message)
except pagure.exceptions.PagureException as msg:
flask.g.session.rollback()
flask.flash(msg, "error")
except SQLAlchemyError as err: # pragma: no cover
flask.g.session.rollback()
flask.flash(str(err), "error")
return flask.redirect(flask.url_for("ui_ns.user_settings"))
开发者ID:Pagure,项目名称:pagure,代码行数:37,
示例30: remove_user_email
点赞 5
# 需要导入模块: import flask [as 别名]
# 或者: from flask import flash [as 别名]
def remove_user_email():
""" Remove the specified email from the logged in user.
"""
if admin_session_timedout():
return flask.redirect(
flask.url_for("auth_login", next=flask.request.url)
)
user = _get_user(username=flask.g.fas_user.username)
if len(user.emails) == 1:
flask.flash("You must always have at least one email", "error")
return flask.redirect(flask.url_for("ui_ns.user_settings"))
form = pagure.forms.UserEmailForm()
if form.validate_on_submit():
email = form.email.data
useremails = [mail.email for mail in user.emails]
if email not in useremails:
flask.flash(
"You do not have the email: %s, nothing to remove" % email,
"error",
)
return flask.redirect(flask.url_for("ui_ns.user_settings"))
for mail in user.emails:
if mail.email == email:
user.emails.remove(mail)
break
try:
flask.g.session.commit()
flask.flash("Email removed")
except SQLAlchemyError as err: # pragma: no cover
flask.g.session.rollback()
_log.exception(err)
flask.flash("Email could not be removed", "error")
return flask.redirect(flask.url_for("ui_ns.user_settings"))
开发者ID:Pagure,项目名称:pagure,代码行数:42,
注:本文中的flask.flash方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。