Skip to content

Commit

Permalink
Flash message on action errors.
Browse files Browse the repository at this point in the history
Closes #8.
  • Loading branch information
lemon24 committed Feb 28, 2018
1 parent 74c0641 commit 2786602
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
14 changes: 10 additions & 4 deletions reader/app.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions reader/templates/entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<br>


{% with messages = get_flashed_messages() %}
{% if messages %}
<p id="messages"><b>{% for message in messages %}{{ message }}. {% endfor %}</b></p>
{% endif %}
{% endwith %}


{% for feed, entry in entries %}

Expand Down
8 changes: 7 additions & 1 deletion reader/templates/feeds.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
<button type="submit" name="action" value="add-feed">add feed</button>

<input type="hidden" name="next" value='{{ url_for('.feeds', **request.args) }}'>

</small>
</form>
<br>


{% with messages = get_flashed_messages() %}
{% if messages %}
<p id="messages"><b>{% for message in messages %}{{ message }}. {% endfor %}</b></p>
{% endif %}
{% endwith %}


{% for feed in feeds %}

<form action="{{ url_for('.update_entries') }}" method="post" id="feed-{{ loop.index }}" class="feed">
Expand Down

0 comments on commit 2786602

Please sign in to comment.