aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/controllers/article.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-07-02 18:56:27 +0200
committerCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-07-02 18:56:27 +0200
commitb43010d2da88d91e8934ba7214a823453cbf6031 (patch)
tree6e8e1fd8d45832a59f8ec37e2009cc68069f2375 /pyaggr3g470r/controllers/article.py
parentDisplay a picto when a feed is disabled due to errors when retrieving. (diff)
parentusing conf.DEFAULT_MAX_ERROR in feed template (diff)
downloadnewspipe-b43010d2da88d91e8934ba7214a823453cbf6031.tar.gz
newspipe-b43010d2da88d91e8934ba7214a823453cbf6031.tar.bz2
newspipe-b43010d2da88d91e8934ba7214a823453cbf6031.zip
Merged in jaesivsm/pyaggr3g470r (pull request #14)
Master
Diffstat (limited to 'pyaggr3g470r/controllers/article.py')
-rw-r--r--pyaggr3g470r/controllers/article.py47
1 files changed, 43 insertions, 4 deletions
diff --git a/pyaggr3g470r/controllers/article.py b/pyaggr3g470r/controllers/article.py
index d22911bd..70b9d2dd 100644
--- a/pyaggr3g470r/controllers/article.py
+++ b/pyaggr3g470r/controllers/article.py
@@ -1,9 +1,14 @@
+import re
+import logging
from sqlalchemy import func
from bootstrap import db
from .abstract import AbstractController
+from pyaggr3g470r.controllers import FeedController
from pyaggr3g470r.models import Article
+logger = logging.getLogger(__name__)
+
class ArticleController(AbstractController):
_db_cls = Article
@@ -21,8 +26,42 @@ class ArticleController(AbstractController):
continue
yield id_
- def get_unread(self):
+ def count_by_feed(self, **filters):
+ if self.user_id:
+ filters['user_id'] = self.user_id
return dict(db.session.query(Article.feed_id, func.count(Article.id))
- .filter(*self._to_filters(readed=False,
- user_id=self.user_id))
- .group_by(Article.feed_id).all())
+ .filter(*self._to_filters(**filters))
+ .group_by(Article.feed_id).all())
+
+ def create(self, **attrs):
+ # handling special denorm for article rights
+ assert 'feed_id' in attrs
+ feed = FeedController(
+ attrs.get('user_id', self.user_id)).get(id=attrs['feed_id'])
+ if 'user_id' in attrs:
+ assert feed.user_id == attrs['user_id'] or self.user_id is None
+ attrs['user_id'] = feed.user_id
+
+ # handling feed's filters
+ for filter_ in feed.filters or []:
+ match = False
+ if filter_.get('type') == 'regex':
+ match = re.match(filter_['pattern'], attrs.get('title', ''))
+ elif filter_.get('type') == 'simple match':
+ match = filter_['pattern'] in attrs.get('title', '')
+ take_action = match and filter_.get('action on') == 'match' \
+ or not match and filter_.get('action on') == 'no match'
+
+ if not take_action:
+ continue
+
+ if filter_.get('action') == 'mark as read':
+ attrs['readed'] = True
+ logger.warn("article %s will be created as read",
+ attrs['link'])
+ elif filter_.get('action') == 'mark as favorite':
+ attrs['like'] = True
+ logger.warn("article %s will be created as liked",
+ attrs['link'])
+
+ return super().create(**attrs)
bgstack15