From 278660273e4c3ba3db59f10b9bb8769f49401661 Mon Sep 17 00:00:00 2001 From: Adrian Damian Date: Wed, 28 Feb 2018 22:27:39 +0200 Subject: [PATCH] Flash message on action errors. Closes #8. --- reader/app.py | 14 ++++++++++---- reader/templates/entries.html | 6 ++++++ reader/templates/feeds.html | 8 +++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/reader/app.py b/reader/app.py index b267765e..1f2af819 100644 --- a/reader/app.py +++ b/reader/app.py @@ -1,10 +1,10 @@ import json from urllib.parse import urlparse, urljoin -from flask import Flask, render_template, current_app, g, request, redirect, abort, Blueprint +from flask import Flask, render_template, current_app, g, request, redirect, abort, Blueprint, flash import humanize -from . import Reader +from . import Reader, ReaderError blueprint = Blueprint('reader', __name__) @@ -75,8 +75,13 @@ def dispatch(self): if self.really[func]: really = request.form.get('really') if really != 'really': - return "really not checked", 400 - func() + flash("really not checked") + return redirect(next) + try: + func() + except ReaderError as e: + flash("error: {}".format(e)) + return redirect(next) return redirect(next) def __call__(self, func=None, *, really=False): @@ -147,6 +152,7 @@ def add_feed(): def create_app(db_path): app = Flask(__name__) app.config['READER_DB'] = db_path + app.secret_key = 'secret' app.teardown_appcontext(close_db) app.register_blueprint(blueprint) return app diff --git a/reader/templates/entries.html b/reader/templates/entries.html index e3f2468a..690f8e3d 100644 --- a/reader/templates/entries.html +++ b/reader/templates/entries.html @@ -41,6 +41,12 @@
+{% with messages = get_flashed_messages() %} +{% if messages %} +

{% for message in messages %}{{ message }}. {% endfor %}

+{% endif %} +{% endwith %} + {% for feed, entry in entries %} diff --git a/reader/templates/feeds.html b/reader/templates/feeds.html index ae90cad6..0c0e9aab 100644 --- a/reader/templates/feeds.html +++ b/reader/templates/feeds.html @@ -17,12 +17,18 @@ -
+{% with messages = get_flashed_messages() %} +{% if messages %} +

{% for message in messages %}{{ message }}. {% endfor %}

+{% endif %} +{% endwith %} + + {% for feed in feeds %}