diff options
Diffstat (limited to 'newspipe/web/views/views.py')
-rw-r--r-- | newspipe/web/views/views.py | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/newspipe/web/views/views.py b/newspipe/web/views/views.py index d587bd09..1fde12c7 100644 --- a/newspipe/web/views/views.py +++ b/newspipe/web/views/views.py @@ -2,8 +2,7 @@ import sys import logging import operator from datetime import datetime, timedelta -from flask import (request, render_template, flash, - url_for, redirect, current_app) +from flask import request, render_template, flash, url_for, redirect, current_app from flask_babel import gettext from sqlalchemy import desc @@ -20,26 +19,26 @@ logger = logging.getLogger(__name__) def authentication_required(error): if API_ROOT in request.url: return error - flash(gettext('Authentication required.'), 'info') - return redirect(url_for('login')) + flash(gettext("Authentication required."), "info") + return redirect(url_for("login")) @current_app.errorhandler(403) def authentication_failed(error): if API_ROOT in request.url: return error - flash(gettext('Forbidden.'), 'danger') - return redirect(url_for('login')) + flash(gettext("Forbidden."), "danger") + return redirect(url_for("login")) @current_app.errorhandler(404) def page_not_found(error): - return render_template('errors/404.html'), 404 + return render_template("errors/404.html"), 404 @current_app.errorhandler(500) def internal_server_error(error): - return render_template('errors/500.html'), 500 + return render_template("errors/500.html"), 500 @current_app.errorhandler(AssertionError) @@ -47,7 +46,7 @@ def handle_sqlalchemy_assertion_error(error): return error.args[0], 400 -@current_app.route('/popular', methods=['GET']) +@current_app.route("/popular", methods=["GET"]) @etag_match def popular(): """ @@ -57,11 +56,12 @@ def popular(): # 'not_created_before' # ie: not_added_before = date_last_added_feed - nb_days try: - nb_days = int(request.args.get('nb_days', 365)) + nb_days = int(request.args.get("nb_days", 365)) except ValueError: nb_days = 10000 - last_added_feed = FeedController().read().\ - order_by(desc('created_date')).limit(1).all() + last_added_feed = ( + FeedController().read().order_by(desc("created_date")).limit(1).all() + ) if last_added_feed: date_last_added_feed = last_added_feed[0].created_date else: @@ -69,25 +69,27 @@ def popular(): not_added_before = date_last_added_feed - timedelta(days=nb_days) filters = {} - filters['created_date__gt'] = not_added_before - filters['private'] = False - filters['error_count__lt'] = conf.DEFAULT_MAX_ERROR + filters["created_date__gt"] = not_added_before + filters["private"] = False + filters["error_count__lt"] = conf.DEFAULT_MAX_ERROR feeds = FeedController().count_by_link(**filters) - sorted_feeds = sorted(list(feeds.items()), key=operator.itemgetter(1), - reverse=True) - return render_template('popular.html', popular=sorted_feeds) + sorted_feeds = sorted(list(feeds.items()), key=operator.itemgetter(1), reverse=True) + return render_template("popular.html", popular=sorted_feeds) -@current_app.route('/about', methods=['GET']) +@current_app.route("/about", methods=["GET"]) @etag_match def about(): - return render_template('about.html', contact=ADMIN_EMAIL) + return render_template("about.html", contact=ADMIN_EMAIL) -@current_app.route('/about/more', methods=['GET']) + +@current_app.route("/about/more", methods=["GET"]) @etag_match def about_more(): - return render_template('about_more.html', - newspipe_version=__version__.split()[1], - registration=[conf.SELF_REGISTRATION and 'Open' or 'Closed'][0], - python_version="{}.{}.{}".format(*sys.version_info[:3]), - nb_users=UserController().read().count()) + return render_template( + "about_more.html", + newspipe_version=__version__.split()[1], + registration=[conf.SELF_REGISTRATION and "Open" or "Closed"][0], + python_version="{}.{}.{}".format(*sys.version_info[:3]), + nb_users=UserController().read().count(), + ) |