Skip to content
Myr

Merge pull request #687 from poiati/flash-signal

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Flash messages signals

authored by Armin Ronacher · committed by Armin Ronacher · parents 0a29c29, b2aae04 · Browse files · 4 files+32 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+32 added−1 removed

  • other:+32 added−1 removed

4 files+32 added−1 removed

modified:flask/testsuite/signals.py+27 added
6 unmodified lines
78 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from __future__ import with_statement1213import flask14import unittest15from flask.testsuite import FlaskTestCase16
79 unmodified lines
96 self.assert_(isinstance(recorded[0], ZeroDivisionError))97 finally:98 flask.got_request_exception.disconnect(record, app)99100 def test_flash_signal(self):101 app = flask.Flask(__name__)102 app.config['SECRET_KEY'] = 'secret'103104 @app.route('/')105 def index():106 flask.flash('This is a flash message', category='notice')107 return flask.redirect('/other')108109 recorded = []110 def record(sender, message, category):111 recorded.append((message, category))112113 flask.message_flashed.connect(record, app)114 try:115 client = app.test_client()116 with client.session_transaction():117 client.get('/')118 self.assert_equal(len(recorded), 1)119 message, category = recorded[0]120 self.assert_equal(message, 'This is a flash message')121 self.assert_equal(category, 'notice')122 finally:123 flask.message_flashed.disconnect(record, app)124125126def suite():127 suite = unittest.TestSuite()128 if flask.signals_available:129 suite.addTest(unittest.makeSuite(SignalsTestCase))
1 unmodified line
modified:flask/__init__.py+1 added-1 removed
32 unmodified lines
3334# the signals35from .signals import signals_available, template_rendered, request_started, \36 request_finished, got_request_exception, request_tearing_down, \37 appcontext_tearing_down37 appcontext_tearing_down, message_flashed3839# We're not exposing the actual json module but a convenient wrapper around40# it.41from . import json
8 unmodified lines
modified:flask/helpers.py+3 added
33 unmodified lines
34 from werkzeug.utils import wrap_file3536from jinja2 import FileSystemLoader3738from .signals import message_flashed39from .globals import session, _request_ctx_stack, _app_ctx_stack, \40 current_app, request4142
318 unmodified lines
361 # implementations that use external storage for keeping their keys/values.362 flashes = session.get('_flashes', [])363 flashes.append((category, message))364 session['_flashes'] = flashes365 message_flashed.send(current_app._get_current_object(),366 message=message, category=category)367368369def get_flashed_messages(with_categories=False, category_filter=[]):370 """Pulls all flashed messages from the session and returns them.
475 unmodified lines
modified:flask/signals.py+1 added
48 unmodified lines
49request_finished = _signals.signal('request-finished')50request_tearing_down = _signals.signal('request-tearing-down')51got_request_exception = _signals.signal('got-request-exception')52appcontext_tearing_down = _signals.signal('appcontext-tearing-down')53message_flashed = _signals.signal('message-flashed')