Python flask.get_flashed_messages() Examples

The following are code examples for showing how to use flask.get_flashed_messages(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: zspider   Author: Zephor5   File: tasks.py    MIT License 6 votes vote down vote up
def task_list():
    field = request.args.get('field', '')
    q = request.args.get('q', '')
    context = {
        'flashes': get_flashed_messages(with_categories=True),
        'prev_kwargs': {}
    }
    q_params = {}
    if q and field:
        if field == 'task_name':
            q_params = {'name__contains': q}
        context['prev_kwargs'] = {
            'field': field,
            'q': q
        }
    page = int(request.args.get('page', 1))
    context.update({
        'count': Task.objects(**q_params).count(),
        'running_count': Task.objects(is_active=True, **q_params).count(),
        'tasks': Task.objects(**q_params).paginate(page=page, per_page=32)
    })
    if context['count'] == 0:
        context['prev_kwargs'] = {}
    return render_template('task/list.html', **context) 
Example 2
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: basic.py    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 3
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: basic.py    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
Project: flasky   Author: RoseOu   File: basic.py    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 5
Project: Flask_Blog   Author: sugarguo   File: basic.py    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
Project: platzi-hello-gae   Author: xertica-cloud   File: basic.py    GNU General Public License v2.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
Project: tesismometro   Author: joapaspe   File: basic.py    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 8
Project: neo4j-social-network   Author: bestvibes   File: basic.py    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 9
Project: neo4j-social-network   Author: bestvibes   File: basic.py    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 10
Project: AneMo   Author: jspargo   File: basic.py    GNU General Public License v2.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 11
Project: oa_qian   Author: sunqb   File: basic.py    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 12
Project: Flask-Toastr   Author: wiltonsr   File: flask_toastr.py    MIT License 5 votes vote down vote up
def message():
        toastr_options = 'toastr.options.closeButton = %s; \
        toastr.options.timeOut = %s; \
        toastr.options.extendedTimeOut = %s; \
        toastr.options.positionClass = \"%s\"; \
        toastr.options.preventDuplicates = %s; \
        toastr.options.newestOnTop = %s; \
        toastr.options.progressBar = %s; ' % (
            current_app.config.get('TOASTR_CLOSE_BUTTON'),
            current_app.config.get('TOASTR_TIMEOUT'),
            current_app.config.get('TOASTR_EXTENDED_TIMEOUT'),
            current_app.config.get('TOASTR_POSITION_CLASS'),
            current_app.config.get('TOASTR_PREVENT_DUPLICATES'),
            current_app.config.get('TOASTR_NEWS_ON_TOP'),
            current_app.config.get('TOASTR_PROGRESS_BAR'))
        message = Template('''
{% with messages = get_flashed_messages(with_categories=true) %}
  {% if messages %}
    <script type="text/javascript">
      (function($) {
        $(document).ready(function() {
          {{ toastr_options }}
          {% for category, message in messages %}
            {% if category is undefined or category == 'message' %}
              toastr.info(\'{{ message }}\', \'{{ category|capitalize }}\')
            {% else %}
              toastr.{{ category }}(\'{{ message }}\', \'{{ category|capitalize }}\')
            {% endif %}
          {% endfor %}
        });
      })(jQuery);
    </script>
  {% endif %}
{% endwith %}
''')
        return Markup(render_template(message,
            get_flashed_messages=get_flashed_messages,
            toastr_options=toastr_options)) 
Example 13
Project: Where2Eat   Author: thetimothyp   File: basic.py    Creative Commons Zero v1.0 Universal 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
Project: PennApps2015-Heartmates   Author: natanlailari   File: basic.py    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 15
Project: noobotkit   Author: nazroll   File: basic.py    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 16
Project: mara-app   Author: mara   File: layout.py    MIT License 5 votes vote down vote up
def flash_messages(response: mara_page.response.Response) -> xml.XMLElement:
    """Displays flask flash messages"""
    return [_.div(id='alerts'),
            _.script(type='text/javascript')[
                map(lambda m: 'showAlert("' + m[1].replace('"', '&quot;') + '","' + (
                    m[0] if m[0] != 'message' else 'info') + '");',
                    flask.get_flashed_messages(True))

            ]] 
Example 17
Project: xuemc   Author: skycucumber   File: basic.py    GNU General Public License v2.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 18
Project: chihu   Author: yelongyu   File: basic.py    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 19
Project: white   Author: whiteclover   File: flash.py    GNU General Public License v2.0 5 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 20
Project: fame   Author: certsocietegenerale   File: negotiation.py    GNU General Public License v3.0 5 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 21
Project: zspider   Author: Zephor5   File: admin.py    MIT License 5 votes vote down vote up
def user_list():
    context = {
        'count': User.objects.count(),
        'flashes': get_flashed_messages()
    }
    page = int(request.args.get('page', 1))
    context.update({'users': User.objects.order_by('role', 'username').paginate(page=page, per_page=32)})
    return render_template('user/list.html', **context) 
Example 22
Project: url_shortener   Author: martydill   File: basic.py    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 23
Project: musapaedia   Author: rossgoodwin   File: basic.py    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 24
Project: cl-auto-reply   Author: KanagiMiss   File: basic.py    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 25
Project: Backend   Author: LockScreen   File: basic.py    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 26
Project: islam-buddy   Author: hamir   File: basic.py    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 27
Project: DevFest-MaxBond   Author: aiyyoi   File: basic.py    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 28
Project: that-startpage-rocks   Author: the-duck   File: basic.py    GNU Lesser 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 29
Project: Tellal   Author: mehtapgundogan   File: basic.py    GNU General Public License v2.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 30
Project: Flask-P2P   Author: chalasr   File: basic.py    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 31
Project: taskqueue   Author: matthappens   File: basic.py    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 32
Project: WRGameVideos-API   Author: thundernet8   File: basic.py    GNU General Public License v2.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 33
Project: pipa-pay-server   Author: davidvon   File: basic.py    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 34
Project: qingmi   Author: xiongxianzhu   File: jinja.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def alert_filter(self, form=None, style='danger'):
        error = first_error(form)
        if error:
            return self.alert_msg(error, style)

        messages = get_flashed_messages(with_categories=True)
        if messages and messages[-1][1] != 'Please log in to access this page.':
            return self.alert_msg(messages[-1][1], messages[-1][0] or 'danger')
        return '' 
Example 35
Project: Mastering-Flask-Web-Development-Second-Edition   Author: PacktPublishing   File: controllers.py    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 36
Project: Ridr_app   Author: RydrDojo   File: basic.py    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 37
Project: myblog   Author: fushall   File: __init__.py    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 38
Project: duelistDB   Author: YesIndeed   File: basic.py    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 39
Project: sentimizer   Author: sarthfrey   File: basic.py    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 40
Project: capybara   Author: AkihikoITOH   File: basic.py    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 41
Project: mybooks-flask   Author: wallisyan   File: test.py    MIT License 5 votes vote down vote up
def error_page():
    errors = get_flashed_messages(with_categories=False,category_filter=['warning'])  # 取出请求当中的信息,
    # with_categories=True:带类别显示,以元祖形式显示[('info', '超时'), ('warning', '超时')]
    # with_categories=False:不带类别显示,是一个列表['超时', '超时'],
    # category_filter:过滤消息的category
    print(errors)
    return json.dumps(errors) 
Example 42
Project: magik   Author: mrinalabrol   File: basic.py    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 43
Project: syntheticmass   Author: synthetichealth   File: basic.py    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 44
Project: plask   Author: theDarkForce   File: basic.py    GNU Lesser 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 45
Project: CTFd   Author: CTFd   File: __init__.py    Apache License 2.0 5 votes vote down vote up
def get_infos():
    return get_flashed_messages(category_filter=request.endpoint + ".infos") 
Example 46
Project: CTFd   Author: CTFd   File: __init__.py    Apache License 2.0 5 votes vote down vote up
def get_errors():
    return get_flashed_messages(category_filter=request.endpoint + ".errors") 
Example 47
Project: optimizers   Author: crowdhackathon-transport   File: basic.py    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 48
Project: WRGameVideos-Server   Author: thundernet8   File: basic.py    GNU General Public License v2.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 49
Project: cron   Author: kartikluke   File: basic.py    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 50
Project: PIL-RCE-Ghostscript-CVE-2018-16509   Author: farisv   File: app.py    MIT License 4 votes vote down vote up
def upload_file():
    if request.method == 'POST':
        file = request.files.get('image', None)

        if not file:
            flash('No image found')
            return redirect(request.url)

        filename = file.filename
        ext = path.splitext(filename)[1]

        if (ext not in ['.jpg', '.jpeg', '.png', '.gif', '.bmp']):
            flash('Invalid extension')
            return redirect(request.url)

        tmp = tempfile.mktemp("test")
        img_path = "{}.{}".format(tmp, ext)

        file.save(img_path)

        img = Image.open(img_path)
        w, h = img.size
        ratio = 256.0 / max(w, h)

        resized_img = img.resize((int(w * ratio), int(h * ratio)))
        resized_img.save(img_path)

        r = make_response()
        r.data = open(img_path, "rb").read()
        r.headers['Content-Disposition'] = 'attachment; filename=resized_{}'.format(filename)

        unlink(img_path)

        return r

    return render_template_string('''
    <!doctype html>
    <title>Image Resizer</title>
    <h1>Upload an Image to Resize</h1>
    {% with messages = get_flashed_messages() %}
    {% if messages %}
        <ul class=flashes>
        {% for message in messages %}
        <li>{{ message }}</li>
        {% endfor %}
        </ul>
    {% endif %}
    {% endwith %}
    <form method=post enctype=multipart/form-data>
      <p><input type=file name=image>
         <input type=submit value=Upload>
    </form>
    ''')