commit 20cf734bb15c556b3a408a0ae821b980d93c8ca0
parent 366c8f957d624d7aa0850945d0b21fb9e3e71535
Author: parazyd <parazyd@dyne.org>
Date: Wed, 16 Jan 2019 22:39:01 +0100
Fix TODO where story_id is not in database.
Diffstat:
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/diaspora.py b/diaspora.py
@@ -72,9 +72,9 @@ def edit():
Route for editing and redacting.
"""
if request.method != 'POST':
- story_id = request.args.get('id')
- if story_id:
- return render_template('edit.html', story=get_story(story_id))
+ story = get_story(request.args.get('id'))
+ if story:
+ return render_template('edit.html', story=story)
return render_template('fail_edit.html')
vals = [
diff --git a/templates/view.html b/templates/view.html
@@ -6,6 +6,8 @@
<main role="main" class="container cover">
+ {% if story %}
+
<h1 class="cover-heading">{{ story['name'] }} in {{ story['disembarkname'] }}</h1>
<p>by {{ story['name'] }}, {{ story['date'] }} {{ story['time'] }}</p>
@@ -16,6 +18,16 @@
<hr style="width: 100%; height: 2px;">
<a href="/country?id={{ story['disembark'] }}">< back</a>
+ {% else %}
+
+ <h1 class="cover-heading">Error!</h1>
+
+ <p class="lead">No story with this story id.</p>
+
+ <p class="lead">You can return to the <a href="/">homepage</a> now.</p>
+
+ {% endif %}
+
</main>
{% include 'footer.html' %}
diff --git a/utils.py b/utils.py
@@ -78,8 +78,12 @@ def get_story(story_id):
"""
Returns a specific story matching the story_id.
"""
- # TODO: test if story_id isn't in db.
- return fill_story(sql_select_col_where('*', 'id', story_id)[0])
+ if not story_id:
+ return None
+ res = sql_select_col_where('*', 'id', story_id)
+ if not res:
+ return None
+ return fill_story(res[0])
def get_multiple_stories(col, val, reverse=True):