diff options
-rw-r--r-- | newspipe/web/controllers/article.py | 3 | ||||
-rw-r--r-- | newspipe/web/models/article.py | 2 | ||||
-rw-r--r-- | newspipe/web/templates/home.html | 4 | ||||
-rw-r--r-- | newspipe/web/views/article.py | 4 | ||||
-rw-r--r-- | newspipe/web/views/home.py | 55 |
5 files changed, 47 insertions, 21 deletions
diff --git a/newspipe/web/controllers/article.py b/newspipe/web/controllers/article.py index 03342a1f..d5efcb74 100644 --- a/newspipe/web/controllers/article.py +++ b/newspipe/web/controllers/article.py @@ -102,3 +102,6 @@ class ArticleController(AbstractController): ) .order_by(Article.date.desc()) ) + + def read_ordered(self, **filters): + return super().read(**filters).order_by(Article.date.desc()) diff --git a/newspipe/web/models/article.py b/newspipe/web/models/article.py index 8764948c..7fdc4c35 100644 --- a/newspipe/web/models/article.py +++ b/newspipe/web/models/article.py @@ -86,7 +86,7 @@ class Article(db.Model, RightMixin): "date", "retrieved_date", "user_id", - "tags" + "tags", } @staticmethod diff --git a/newspipe/web/templates/home.html b/newspipe/web/templates/home.html index 03bf24e4..cb0ac322 100644 --- a/newspipe/web/templates/home.html +++ b/newspipe/web/templates/home.html @@ -70,7 +70,9 @@ <li id="tab-unread" class="nav-item"> <a class="nav-link {% if filter_ == 'unread' %}active{% endif %}" href="{{ gen_url(filter_='unread') }}">{{ _('Unread') }}</a> </li> - + <li id="tab-unread" class="nav-item"> + <a class="nav-link {% if liked %}active{% endif %}" href="{{ gen_url(liked=not liked) }}">{{ _('Liked') }}</a> + </li> <li id="tab-nbdisplay" class="pull-right"> <div id="nbdisplay"> <a href="{{ gen_url(limit=10) }}" class="badge {% if limit == 10 %}badge-primary{% else %}badge-info{% endif %}">{{ _(10) }}</a> diff --git a/newspipe/web/views/article.py b/newspipe/web/views/article.py index 5fdaec3e..c0c6f346 100644 --- a/newspipe/web/views/article.py +++ b/newspipe/web/views/article.py @@ -103,9 +103,7 @@ def history(year=None, month=None): @article_bp.route("/mark_as/<string:new_value>", methods=["GET"]) -@article_bp.route( - "/mark_as/<string:new_value>/feed/<int:feed_id>", methods=["GET"] -) +@article_bp.route("/mark_as/<string:new_value>/feed/<int:feed_id>", methods=["GET"]) @login_required def mark_as(new_value="read", feed_id=None, article_id=None): """ diff --git a/newspipe/web/views/home.py b/newspipe/web/views/home.py index 9c2e1e68..d5b583d3 100644 --- a/newspipe/web/views/home.py +++ b/newspipe/web/views/home.py @@ -30,28 +30,51 @@ def home(): feeds = {feed.id: feed.title for feed in current_user.feeds} - filter_ = request.args.get('filter_', 'unread') - feed_id = int(request.args.get('feed', 0)) - limit = request.args.get('limit', 1000) + filter_ = request.args.get("filter_", "unread") + feed_id = int(request.args.get("feed", 0)) + liked = int(request.args.get("liked", 0)) == 1 + limit = request.args.get("limit", 1000) + filters = {} + if filter_ in ["read", "unread"]: + filters["readed"] = filter_ == "read" if feed_id: - articles = art_contr.read(readed=(filter_ == 'read'), feed_id=feed_id) - else: - articles = art_contr.read(readed=(filter_ == 'read')) + filters["feed_id"] = feed_id + if liked: + filters["like"] = int(liked) == 1 + + articles = art_contr.read_ordered(**filters) - # articles = articles.order_by(Article.date.desc()) - if limit != 'all': + if limit != "all": limit = int(limit) articles = articles.limit(limit) - in_error = {feed.id: feed.error_count for feed in - FeedController(current_user.id).read(error_count__gt=0).all()} - def gen_url(filter_=filter_, limit=limit, feed=feed_id): - return '?filter_=%s&limit=%s&feed=%d' % (filter_, limit, feed) - return render_template('home.html', gen_url=gen_url, feed_id=feed_id, - filter_=filter_, limit=limit, feeds=feeds, - unread=dict(unread), articles=articles.all(), - in_error=in_error) + in_error = { + feed.id: feed.error_count + for feed in FeedController(current_user.id).read(error_count__gt=0).all() + } + + def gen_url(filter_=filter_, limit=limit, feed=feed_id, liked=liked): + return "?filter_=%s&limit=%s&feed=%d&liked=%s" % ( + filter_, + limit, + feed, + 1 if liked else 0, + ) + + return render_template( + "home.html", + gen_url=gen_url, + feed_id=feed_id, + filter_=filter_, + limit=limit, + feeds=feeds, + liked=liked, + unread=dict(unread), + articles=articles.all(), + in_error=in_error, + ) + def _get_filters(in_dict): filters = {} |