diff options
author | Cédric Bonhomme <kimble.mandel@gmail.com> | 2014-01-06 07:53:55 +0100 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel@gmail.com> | 2014-01-06 07:53:55 +0100 |
commit | 716322058ac9077ad19eb4d8284a82ca2e63e4e6 (patch) | |
tree | 3710ea1035eff3b7315e8c24bd3d43e93e58fb06 | |
parent | Displaying more information in the /feed page. (diff) | |
download | newspipe-716322058ac9077ad19eb4d8284a82ca2e63e4e6.tar.gz newspipe-716322058ac9077ad19eb4d8284a82ca2e63e4e6.tar.bz2 newspipe-716322058ac9077ad19eb4d8284a82ca2e63e4e6.zip |
Minor fix when a feed contains 0 article.
-rw-r--r-- | pyaggr3g470r/templates/feed.html | 14 | ||||
-rw-r--r-- | pyaggr3g470r/views.py | 14 |
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, \ |