diff options
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r-- | pyaggr3g470r/lib/article_utils.py | 14 | ||||
-rw-r--r-- | pyaggr3g470r/lib/crawler.py | 1 | ||||
-rw-r--r-- | pyaggr3g470r/templates/admin/user.html | 4 | ||||
-rw-r--r-- | pyaggr3g470r/templates/feeds.html | 5 | ||||
-rw-r--r-- | pyaggr3g470r/templates/inactives.html | 9 | ||||
-rw-r--r-- | pyaggr3g470r/views/api/common.py | 6 | ||||
-rw-r--r-- | pyaggr3g470r/views/api/feed.py | 1 | ||||
-rw-r--r-- | pyaggr3g470r/views/feed.py | 3 |
8 files changed, 30 insertions, 13 deletions
diff --git a/pyaggr3g470r/lib/article_utils.py b/pyaggr3g470r/lib/article_utils.py index 3c642167..115b6058 100644 --- a/pyaggr3g470r/lib/article_utils.py +++ b/pyaggr3g470r/lib/article_utils.py @@ -35,8 +35,10 @@ 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() + date = datetime.now() for date_key in ('published', 'updated'): if entry.get(date_key): @@ -63,12 +65,12 @@ 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, - 'retrieved_date': now.isoformat(), - 'date': (date or now).isoformat()} + 'retrieved_date': date.isoformat(), + 'date': date.isoformat()} diff --git a/pyaggr3g470r/lib/crawler.py b/pyaggr3g470r/lib/crawler.py index 8d2de15f..de557e45 100644 --- a/pyaggr3g470r/lib/crawler.py +++ b/pyaggr3g470r/lib/crawler.py @@ -143,6 +143,7 @@ class PyAggUpdater(AbstractCrawler): up_feed[key] = fresh_feed[key] if not self.feed.get('title'): up_feed['title'] = fresh_feed.get('title', '') + up_feed['user_id'] = self.feed['user_id'] logger.info('%r %r - pushing feed attrs %r', self.feed['id'], self.feed['title'], 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 @@ <thead> <tr> <th>#</th> - <th>{{ _('Name') }}</th> + <th>{{ _('Title') }}</th> <th>{{ _('Feed link') }}</th> <th>{{ _('Site link') }}</th> <th>{{ _('(unread) articles') }}</th> @@ -34,7 +34,7 @@ {% for feed in user.feeds|sort(attribute="title") %} <tr> <td>{{ loop.index }}</td> - <td><a href="/feed/{{ feed.id }}">{{ feed.title }}</a></td> + <td><a href="{{ url_for("feed.feed", feed_id=feed.id) }}">{%if feed.icon%}<img src="{{ url_for('feed.icon', feed_id=feed.id) }}" width="16px" />{%endif%}{{ feed.title }}</a></td> <td>{{ feed.link }}</td> <td>{{ feed.site_link }}</td> <td>( {{ unread_article_count.get(feed.id, 0) }} ) {{ article_count.get(feed.id, 0) }}</td> 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 @@ <i class="glyphicon glyphicon-exclamation-sign" title="{{ _('Feed encountered too much errors.') }}"></i> {% endif %} </td> - <td><a href="{{ url_for("feed.feed", feed_id=feed.id) }}" {% if feed.description %}title="{{ feed.description }}"{% endif %}>{{ feed.title }}</a></td> + <td><a href="{{ url_for("feed.feed", feed_id=feed.id) }}" {% if feed.description %}title="{{ feed.description }}"{% endif %}> + {% if feed.icon %}<img src="{{ url_for('feed.icon', feed_id=feed.id) }}" width="16px" />{% endif %} + {{ feed.title }} + </a></td> <td><a href="{{ feed.site_link }}">{{ feed.site_link }}</a></td> <td>( {{ unread_article_count.get(feed.id, 0) }} ) {{ article_count.get(feed.id, 0) }}</td> <td> 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 @@ <br /> {% if inactives != [] %} <ul class="list-group"> - {% for item in inactives %} - <li class="list-group-item"><a href="/feed/{{ item[0].id }}">{{ item[0].title }}</a> - {{ item[1].days }} {{ _('days') }}</li> + {% for feed, delta in inactives %} + <li class="list-group-item"> + <a href="{{ url_for('feed.feed', feed_id=feed.id) }}"> + {% if feed.icon %}<img src="{{ url_for('feed.icon', feed_id=feed.id) }}" width="16px" />{% endif %} + {{ feed.title }} + </a> - {{ delta.days }} {{ _('days') }} + </li> {% endfor %} </ul> {% else %} diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py index b8c4dd9d..a7068807 100644 --- a/pyaggr3g470r/views/api/common.py +++ b/pyaggr3g470r/views/api/common.py @@ -143,7 +143,11 @@ class PyAggResourceExisting(PyAggAbstractResource): args = self.reqparse_args(default=False) new_values = {key: args[key] for key in set(args).intersection(self.attrs)} - self.controller.update({'id': obj_id}, new_values) + if 'user_id' in new_values and g.user.is_admin(): + controller = self.wider_controller + else: + controller = self.controller + return controller.update({'id': obj_id}, new_values), 200 def delete(self, obj_id=None): """delete a object""" diff --git a/pyaggr3g470r/views/api/feed.py b/pyaggr3g470r/views/api/feed.py index f9060263..530f3fef 100644 --- a/pyaggr3g470r/views/api/feed.py +++ b/pyaggr3g470r/views/api/feed.py @@ -16,6 +16,7 @@ from pyaggr3g470r.views.api.common import PyAggAbstractResource, \ FEED_ATTRS = {'title': {'type': str}, 'description': {'type': str}, 'link': {'type': str}, + 'user_id': {'type': int}, 'site_link': {'type': str}, 'enabled': {'type': bool, 'default': True}, 'etag': {'type': str, 'default': ''}, 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/<int:feed_id>', 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: |