From 30b48eb41a9515feaf7dbc5cd4eb8847371b237c Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Mon, 6 Jul 2015 21:21:52 +0200 Subject: adding feed icons on feed pages --- pyaggr3g470r/lib/article_utils.py | 8 +++++--- pyaggr3g470r/templates/admin/user.html | 4 ++-- pyaggr3g470r/templates/feeds.html | 5 ++++- pyaggr3g470r/templates/inactives.html | 9 +++++++-- pyaggr3g470r/views/feed.py | 3 ++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pyaggr3g470r/lib/article_utils.py b/pyaggr3g470r/lib/article_utils.py index 3c642167..79ac34f5 100644 --- a/pyaggr3g470r/lib/article_utils.py +++ b/pyaggr3g470r/lib/article_utils.py @@ -35,6 +35,8 @@ def extract_id(entry, keys=[('link', 'link'), def construct_article(entry, feed): + if hasattr(feed, 'dump'): # this way can be a sqlalchemy obj or a dict + feed = feed.dump() "Safe method to transorm a feedparser entry into an article" now = datetime.now() @@ -63,10 +65,10 @@ def construct_article(entry, feed): logger.warning("Unable to get the real URL of %s. Error: %s", article_link, error) - return {'feed_id': feed.id, - 'user_id': feed.user_id, + return {'feed_id': feed['id'], + 'user_id': feed['user_id'], 'entry_id': extract_id(entry).get('entry_id', None), - 'link': entry.get('link', feed.site_link), + 'link': entry.get('link', feed['site_link']), 'title': entry.get('title', 'No title'), 'readed': False, 'like': False, 'content': content, diff --git a/pyaggr3g470r/templates/admin/user.html b/pyaggr3g470r/templates/admin/user.html index e50741ee..21bcd6b6 100644 --- a/pyaggr3g470r/templates/admin/user.html +++ b/pyaggr3g470r/templates/admin/user.html @@ -23,7 +23,7 @@ # - {{ _('Name') }} + {{ _('Title') }} {{ _('Feed link') }} {{ _('Site link') }} {{ _('(unread) articles') }} @@ -34,7 +34,7 @@ {% for feed in user.feeds|sort(attribute="title") %} {{ loop.index }} - {{ feed.title }} + {%if feed.icon%}{%endif%}{{ feed.title }} {{ feed.link }} {{ feed.site_link }} ( {{ unread_article_count.get(feed.id, 0) }} ) {{ article_count.get(feed.id, 0) }} diff --git a/pyaggr3g470r/templates/feeds.html b/pyaggr3g470r/templates/feeds.html index 789decf5..20e0cccb 100644 --- a/pyaggr3g470r/templates/feeds.html +++ b/pyaggr3g470r/templates/feeds.html @@ -28,7 +28,10 @@ {% endif %} - {{ feed.title }} + + {% if feed.icon %}{% endif %} + {{ feed.title }} + {{ feed.site_link }} ( {{ unread_article_count.get(feed.id, 0) }} ) {{ article_count.get(feed.id, 0) }} diff --git a/pyaggr3g470r/templates/inactives.html b/pyaggr3g470r/templates/inactives.html index 6a4ff055..eb546eca 100644 --- a/pyaggr3g470r/templates/inactives.html +++ b/pyaggr3g470r/templates/inactives.html @@ -9,8 +9,13 @@
{% if inactives != [] %} {% else %} diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 3556d7c7..18e110af 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -189,7 +189,8 @@ def process_form(feed_id=None): @feed_bp.route('/icon/', methods=['GET']) @login_required def icon(feed_id): - icon = FeedController(g.user.id).get(id=feed_id).icon + icon = FeedController(None if g.user.is_admin() else g.user.id)\ + .get(id=feed_id).icon etag = md5(icon.encode('utf8')).hexdigest() headers = {'Cache-Control': 'max-age=86400', 'ETag': etag} if request.headers.get('if-none-match') == etag: -- cgit