Python flask.get_flashed_messages() Examples

The following are 20 code examples of flask.get_flashed_messages(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask , or try the search function .
Example #1
Source File: negotiation.py    From fame with GNU General Public License v3.0 6 votes vote down vote up
def validation_error(path=None):
    if choose_media_type(acceptable_media_types(request), [html]):
        if path:
            return flask_redirect(path)
        else:
            return flask_redirect(request.referrer)
    else:
        return render_json({'errors': get_flashed_messages()}) 
Example #2
Source File: flash.py    From white with GNU General Public License v2.0 6 votes vote down vote up
def render(self):
        messages = get_flashed_messages(with_categories=True)
        if messages:
            html = '<div class="notifications">\n'
            for category, message in messages:
                html += '<p class="%s">%s</p>\n' % (category, message)
            html += '</div>'
            return html
        return '' 
Example #3
Source File: basic.py    From Flask with Apache License 2.0 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #4
Source File: basic.py    From Flask with Apache License 2.0 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #5
Source File: basic.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #6
Source File: basic.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #7
Source File: basic.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #8
Source File: basic.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #9
Source File: basic.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #10
Source File: base.py    From incubator-superset with Apache License 2.0 5 votes vote down vote up
def common_bootstrap_payload() -> Dict[str, Any]:
    """Common data always sent to the client"""
    messages = get_flashed_messages(with_categories=True)
    locale = str(get_locale())

    return {
        "flash_messages": messages,
        "conf": {k: conf.get(k) for k in FRONTEND_CONF_KEYS},
        "locale": locale,
        "language_pack": get_language_pack(locale),
        "feature_flags": get_feature_flags(),
        "menu_data": menu_data(),
    } 
Example #11
Source File: __init__.py    From CTFd with Apache License 2.0 5 votes vote down vote up
def get_errors():
    return get_flashed_messages(category_filter=request.endpoint + ".errors") 
Example #12
Source File: __init__.py    From CTFd with Apache License 2.0 5 votes vote down vote up
def get_infos():
    return get_flashed_messages(category_filter=request.endpoint + ".infos") 
Example #13
Source File: basic.py    From syntheticmass with Apache License 2.0 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #14
Source File: __init__.py    From myblog with GNU General Public License v3.0 5 votes vote down vote up
def __call__(self):

        messages = ''
        for (cate, msg) in get_flashed_messages(with_categories=True):
            if cate == 'message':
                cate = 'warning'
            messages += _TEMPLATE.format(message=msg, category=cate)

        return Markup(messages) 
Example #15
Source File: controllers.py    From Mastering-Flask-Web-Development-Second-Edition with MIT License 5 votes vote down vote up
def make_cache_key(*args, **kwargs):
    path = request.path
    args = str(hash(frozenset(request.args.items())))
    messages = str(hash(frozenset(get_flashed_messages())))
    if current_user.is_authenticated:
        roles = str(current_user.roles)
    else:
        roles = ""
    return (path + args + roles + session.get('locale', '') + messages).encode('utf-8') 
Example #16
Source File: __init__.py    From c3bottles with MIT License 5 votes vote down vote up
def before_request():
    g.alerts = get_flashed_messages()
    g.login_form = LoginForm()
    g.now = datetime.now() 
Example #17
Source File: basic.py    From Flask-P2P with MIT License 5 votes vote down vote up
def test_flashes(self):
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'

        with app.test_request_context():
            self.assert_false(flask.session.modified)
            flask.flash('Zap')
            flask.session.modified = False
            flask.flash('Zip')
            self.assert_true(flask.session.modified)
            self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) 
Example #18
Source File: remedy_utils.py    From radremedy with Mozilla Public License 2.0 5 votes vote down vote up
def get_grouped_flashed_messages():
    """
    Gets the current set of flashed messages and returns them
    grouped by the appropriate Bootstrap contextual alert class.

    Returns:
        A dictionary of all messages, keyed by the appropriate
        Bootstrap contextual alert class.
    """
    # This will contain the lists of flashed messages,
    # keyed by the appropriate contextual Bootstrap class.
    grouped_messages = {
    }

    # Go through the messages
    for category, message in get_flashed_messages(with_categories=True):
        # Try to figure out the contextual class, defaulting to 'alert-info'.
        alert_class = flash_message_classes.get(category, 'alert-info')

        # Set up a list value for the relevant list class if not found.
        if alert_class not in grouped_messages:
            grouped_messages[alert_class] = list()

        grouped_messages[alert_class].append(message)

    return grouped_messages 
Example #19
Source File: misc.py    From burp-ui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def post(self):
        """Propagate a message to the next screen (or whatever reads the session)"""
        def translate(level):
            levels = ['danger', 'warning', 'info', 'success']
            convert = {
                '0': 'success',
                '1': 'warning',
                '2': 'error',
                '3': 'info'
            }
            if not level:
                return 'danger'
            # return the converted value or the one we already had
            new = convert.get(level, level)
            # if the level is not handled, assume 'danger'
            if new not in levels:
                return 'danger'
            return new

        # retrieve last flashed messages so we don't loose anything
        for level, message in get_flashed_messages(with_categories=True):
            flash(message, level)

        args = self.parser.parse_args()
        message = args['message']
        level = translate(args['level'])
        flash(message, level)
        return {'message': message, 'level': level}, 201 
Example #20
Source File: jsonify.py    From evesrp with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def jsonify(*args, **kwargs):
    messages = [{'message': m, 'category':c} for c, m in
            flask.get_flashed_messages(with_categories=True)]
    return flask.jsonify(*args, flashed_messages=messages, **kwargs)