How to use the flask.flash function in Flask

To help you get started, we’ve selected a few Flask examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rmountjoy92 / VectorCloud / vectorcloud / main / utils.py View on Github external
def dock_robot():
    db.session.query(Command).delete()
    robot_command = Command(command='robot.behavior.drive_on_charger()')
    db.session.add(robot_command)
    db.session.commit()

    override_message = 'Dock Command Complete!'
    err_msg = robot_do(override_output=override_message)
    if err_msg != override_message:
        db.session.query(Command).delete()
        db.session.commit()
        flash('No Vector is Connected. Error message: ' + err_msg, 'warning')

    err_msg = get_stats(force=True)
    if err_msg:
        flash('No Vector is Connected. Error message: ' + err_msg, 'warning')
github liwanlei / FXTest / app / users / views.py View on Github external
user = User.query.filter_by(username=session.get('username')).first()
        new_ad = User.query.filter_by(id=id).first()
        if new_ad != user:
            if user.is_sper == 1:
                new_ad.set_password('111111')
                try:
                    db.session.commit()
                    flash(reset_success_message)
                    return redirect(url_for('home.adminuser'))
                except Exception as e:
                    db.session.rollback()
                    flash(user_reset_error)
                    return redirect(url_for('home.adminuser'))
            flash(user_reset_isnot_amin)
            return redirect(url_for('home.adminuser'))
        flash(user_reset_owner)
        return redirect(url_for('home.adminuser'))
github lxc-webpanel / LXC-Web-Panel / lwp.py View on Github external
def check_session_limit():
    if 'logged_in' in session and session.get('last_activity') is not None:
        now = int(time.time())
        limit = now - 60 * int(config.get('session', 'time'))
        last_activity = session.get('last_activity')
        if last_activity < limit:
            flash(u'Session timed out !', 'info')
            logout()
        else:
            session['last_activity'] = now
github SySS-Research / Lauschgeraet / lauschgeraet / flask.py View on Github external
def add_rule():
    if ':' in request.form["olddest"]:
        oldip, oldport = request.form["olddest"].split(':')
    else:
        flash("Your old destination must be of the form :", "danger")
        return render_template("messages.html")
    if ':' in request.form["newdest"]:
        newip, newport = request.form["newdest"].split(':')
    else:
        newip = request.form["newdest"]
        newport = oldport
    out = add_iptables_rule(
        request.form["proto"],
        oldip, oldport,
        newip, newport,
    )
    if out:
        flash("Error while adding rule: %s" % out, "danger")
        return render_template("messages.html")
    return ""
github LMFDB / lmfdb / lmfdb / ecnf / main.py View on Github external
def split_short_class_label(lab):
    r""" Split a short class label into 2 components
    (conductor_label,isoclass_label)
    """
    data = lab.split("-")
    if len(data) != 2:
        flash(Markup("Error: <span style="color:black">%s</span> is not a valid isogeny class label. It must be of the form (conductor label) - (isogeny class label) (separated by dashes), such as 31.1-a" % lab), "error")
        raise ValueError
    conductor_label = data[0]
    isoclass_label = data[1]
    return (conductor_label, isoclass_label)
github agdsn / pycroft / web / blueprints / login / __init__.py View on Github external
def logout():
    logout_user()
    flash(u"Sie sind jetzt abgemeldet!", "info")
    return redirect(url_for(".login"))
github craws / OpenAtlas / openatlas / views / place.py View on Github external
else:
                origin.link('P67', object_)
        Gis.insert(location, form)
        g.cursor.execute('COMMIT')
        if form.continue_.data == 'yes':
            url = url_for('place_insert',
                          origin_id=origin.id if origin else None,
                          system_type=system_type if system_type else None)
        elif form.continue_.data in ['sub', 'human_remains']:
            url = url_for('place_insert', origin_id=object_.id, system_type=form.continue_.data)
        logger.log_user(object_.id, log_action)
        flash(_('entity created') if log_action == 'insert' else _('info update'), 'info')
    except InvalidGeomException as e:  # pragma: no cover
        g.cursor.execute('ROLLBACK')
        logger.log('error', 'database', 'transaction failed because of invalid geom', e)
        flash(_('Invalid geom entered'), 'error')
        url = url_for('place_index') if log_action == 'insert' else url_for('place_index')
    except Exception as e:  # pragma: no cover
        g.cursor.execute('ROLLBACK')
        logger.log('error', 'database', 'transaction failed', e)
        flash(_('error transaction'), 'error')
        url = url_for('place_index') if log_action == 'insert' else url_for('place_index')
    return url
github DOAJ / doaj / portality / view / account.py View on Github external
def login():
    current_info = {'next': request.args.get('next', '')}
    form = LoginForm(request.form, csrf_enabled=False, **current_info)
    if request.method == 'POST' and form.validate():
        password = form.password.data
        username = form.username.data
        user = models.Account.pull(username)
        if user is None:
            user = models.Account.pull_by_email(username)
        try:
            if user is not None and user.check_password(password):
                login_user(user, remember=True)
                flash('Welcome back.', 'success')
                return redirect(get_redirect_target(form=form))
            else:
                flash('Incorrect username/password', 'error')
        except KeyError:
            abort(500)
    if request.method == 'POST' and not form.validate():
        flash('Invalid credentials', 'error')
    return render_template('account/login.html', form=form)
github lxc-webpanel / LXC-Web-Panel / lwp.py View on Github external
if re.match('^(?!^containers$)|[a-zA-Z0-9_-]+$', name):
                out = None

                try:
                    out = lxc.clone(orig=orig, new=name, snapshot=snapshot)
                except lxc.ContainerAlreadyExists:
                    flash(u'The Container %s already exists!' % name, 'error')
                except subprocess.CalledProcessError:
                    flash(u'Can\'t snapshot a directory', 'error')

                if out and out == 0:
                    flash(u'Container %s cloned into %s successfully!'
                          % (orig, name), 'success')
                elif out and out != 0:
                    flash(u'Failed to clone %s into %s!' % (orig, name),
                          'error')

            else:
                if name == '':
                    flash(u'Please enter a container name!', 'error')
                else:
                    flash(u'Invalid name for \"%s\"!' % name, 'error')

        return redirect(url_for('home'))
    return render_template('login.html')