aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyaggr3g470r/templates/feed.html14
-rw-r--r--pyaggr3g470r/views.py14
2 files changed, 18 insertions, 10 deletions
diff --git a/pyaggr3g470r/templates/feed.html b/pyaggr3g470r/templates/feed.html
index b0f06eb6..9825e16b 100644
--- a/pyaggr3g470r/templates/feed.html
+++ b/pyaggr3g470r/templates/feed.html
@@ -8,12 +8,14 @@
<p>This feed contains {{ feed.articles|count }} <a href="/articles/{{ feed.oid }}">articles</a>.</p>
<p>Address of the feed: <a href="{{ feed.link }}">{{ feed.link }}</a>.</p>
<p>Address of the site: <a href="{{ feed.site_link }}">{{ feed.site_link }}</a>.</p>
- <br />
- <p>The last article was posted {{ elapsed.days }} day(s) ago.<br />
- Daily average: {{ average }}, between the {{ first_post_date.strftime('%Y-%m-%d') }} and the {{ end_post_date.strftime('%Y-%m-%d') }}.</p>
- <br />
- <h3>Tag cloud</h3>
- <div>{{ tag_cloud|safe }}</div>
+ {% if feed.articles|count != 0 %}
+ <br />
+ <p>The last article was posted {{ elapsed.days }} day(s) ago.<br />
+ Daily average: {{ average }}, between the {{ first_post_date.strftime('%Y-%m-%d') }} and the {{ end_post_date.strftime('%Y-%m-%d') }}.</p>
+ <br />
+ <h3>Tag cloud</h3>
+ <div>{{ tag_cloud|safe }}</div>
+ {% endif %}
</div>
</div><!-- /.container -->
{% endblock %}
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index af2abc7b..34cdcea7 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -146,10 +146,16 @@ def feed(feed_id=None):
tag_cloud = utils.tag_cloud(top_words)
today = datetime.datetime.now()
- last_article = articles[0].date
- first_article = articles[-1].date
- delta = last_article - first_article
- average = round(float(len(articles)) / abs(delta.days), 2)
+ try:
+ last_article = articles[0].date
+ first_article = articles[-1].date
+ delta = last_article - first_article
+ average = round(float(len(articles)) / abs(delta.days), 2)
+ except:
+ last_article = datetime.datetime.fromtimestamp(0)
+ first_article = datetime.datetime.fromtimestamp(0)
+ delta = last_article - first_article
+ average = 0
elapsed = today - last_article
return render_template('feed.html', head_title=feed.title, feed=feed, tag_cloud=tag_cloud, \
bgstack15