aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2018-10-29 22:43:02 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2018-10-29 22:43:02 +0100
commit3ac2de8ff898cfe2df74e8f1a74dd7ef9c65fb66 (patch)
tree5429e9ccbb6fb7e4b8ae63df90ce1023198c1362 /src
parentUpdated Python dependencies. (diff)
downloadnewspipe-3ac2de8ff898cfe2df74e8f1a74dd7ef9c65fb66.tar.gz
newspipe-3ac2de8ff898cfe2df74e8f1a74dd7ef9c65fb66.tar.bz2
newspipe-3ac2de8ff898cfe2df74e8f1a74dd7ef9c65fb66.zip
Improved the pagination and sorting of the list of articles of the public page.
Diffstat (limited to 'src')
-rw-r--r--src/web/templates/feed.html15
-rw-r--r--src/web/views/feed.py21
2 files changed, 22 insertions, 14 deletions
diff --git a/src/web/templates/feed.html b/src/web/templates/feed.html
index d914b82b..31db94a5 100644
--- a/src/web/templates/feed.html
+++ b/src/web/templates/feed.html
@@ -55,7 +55,7 @@
</tr>
</thead>
<tbody>
- {% for article in feed.articles %}
+ {% for article in articles %}
<tr>
<td><a href="{{ url_for("article.article_pub", article_id=article.id) }}">{{ article.title }}</a></td>
<td>{{ article.date | datetime }}</td>
@@ -67,13 +67,10 @@
</div>
</div>
+ <div class="row">
+ <div class="col-md-8 offset-md-1">
+ {{ pagination.links }}
+ </div>
+ </div>
</div><!-- /.container -->
-<script>
-$(document).ready(function() {
- $('#table-articles').DataTable( {
- responsive: true,
- order: [[1, "desc"]]
- });
-});
-</script>
{% endblock %}
diff --git a/src/web/views/feed.py b/src/web/views/feed.py
index 873e1eb6..385d7de2 100644
--- a/src/web/views/feed.py
+++ b/src/web/views/feed.py
@@ -8,6 +8,7 @@ from flask import Blueprint, render_template, flash, \
redirect, request, url_for
from flask_babel import gettext
from flask_login import login_required, current_user
+from flask_paginate import Pagination, get_page_args
import conf
from lib import misc_utils, utils
@@ -40,17 +41,25 @@ def feed_view(feed_id=None, user_id=None):
category = None
if feed.category_id:
category = CategoryController(user_id).get(id=feed.category_id)
- articles = ArticleController(user_id) \
- .read(feed_id=feed_id) \
- .order_by(desc("date")).all()
+ filters = {}
+ filters['feed_id'] = feed_id
+ articles = ArticleController(user_id).read_light(**filters)
+
+ # Server-side pagination
+ page, per_page, offset = get_page_args(per_page_parameter='per_page')
+ pagination = Pagination(page=page, total=articles.count(),
+ css_framework='bootstrap3',
+ search=False, record_name='articles',
+ per_page=per_page)
today = datetime.now()
try:
last_article = articles[0].date
first_article = articles[-1].date
delta = last_article - first_article
- average = round(float(len(articles)) / abs(delta.days), 2)
- except:
+ average = round(float(articles.count()) / abs(delta.days), 2)
+ except Exception as e:
+ print(e)
last_article = datetime.fromtimestamp(0)
first_article = datetime.fromtimestamp(0)
delta = last_article - first_article
@@ -60,6 +69,8 @@ def feed_view(feed_id=None, user_id=None):
return render_template('feed.html',
head_titles=[utils.clear_string(feed.title)],
feed=feed, category=category,
+ articles=articles.offset(offset).limit(per_page),
+ pagination=pagination,
first_post_date=first_article,
end_post_date=last_article,
average=average, delta=delta, elapsed=elapsed)
bgstack15