diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2018-10-31 22:19:20 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2018-10-31 22:19:20 +0100 |
commit | 5f5b8f0632c843bc568b1d4597f83f8546bf68b6 (patch) | |
tree | 3de65b713c58464eb4bfbd339acd686915613fca /src/web/views | |
parent | Improved the import/export functions for data liberation. It is now possible ... (diff) | |
parent | Removed deug print. (diff) | |
download | newspipe-5f5b8f0632c843bc568b1d4597f83f8546bf68b6.tar.gz newspipe-5f5b8f0632c843bc568b1d4597f83f8546bf68b6.tar.bz2 newspipe-5f5b8f0632c843bc568b1d4597f83f8546bf68b6.zip |
Merge branch 'master' of gitlab.com:newspipe/newspipe
Diffstat (limited to 'src/web/views')
-rw-r--r-- | src/web/views/feed.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/web/views/feed.py b/src/web/views/feed.py index dcc3aa3e..39134213 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, make_response 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,24 @@ 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: last_article = datetime.fromtimestamp(0) first_article = datetime.fromtimestamp(0) delta = last_article - first_article @@ -60,6 +68,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) |