From 03819cbf7cedde10e27d18068070c14ca37ff6e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Fri, 19 Sep 2008 10:40:06 +0200 Subject: [PATCH] Catch all exception in latest_blog_posts catlogue tag. --- apps/catalogue/templatetags/catalogue_tags.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index c315cfed3..3c34e8cdd 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -194,18 +194,21 @@ def latest_blog_posts(feed_url, posts_to_show=5): import feedparser import datetime - feed = feedparser.parse(feed_url) - posts = [] - for i in range(posts_to_show): - pub_date = feed['entries'][i].updated_parsed - published = datetime.date(pub_date[0], pub_date[1], pub_date[2] ) - posts.append({ - 'title': feed['entries'][i].title, - 'summary': feed['entries'][i].summary, - 'link': feed['entries'][i].link, - 'date': published, - }) - return {'posts': posts} + try: + feed = feedparser.parse(feed_url) + posts = [] + for i in range(posts_to_show): + pub_date = feed['entries'][i].updated_parsed + published = datetime.date(pub_date[0], pub_date[1], pub_date[2] ) + posts.append({ + 'title': feed['entries'][i].title, + 'summary': feed['entries'][i].summary, + 'link': feed['entries'][i].link, + 'date': published, + }) + return {'posts': posts} + except: + return {'posts': []} @register.inclusion_tag('catalogue/tag_list.html') -- 2.20.1