diff options
Diffstat (limited to 'newspipe/web/views')
-rw-r--r-- | newspipe/web/views/__init__.py | 46 | ||||
-rw-r--r-- | newspipe/web/views/admin.py | 8 | ||||
-rw-r--r-- | newspipe/web/views/api/v2/__init__.py | 2 | ||||
-rw-r--r-- | newspipe/web/views/api/v2/article.py | 10 | ||||
-rw-r--r-- | newspipe/web/views/api/v2/category.py | 8 | ||||
-rw-r--r-- | newspipe/web/views/api/v2/common.py | 4 | ||||
-rw-r--r-- | newspipe/web/views/api/v2/feed.py | 10 | ||||
-rw-r--r-- | newspipe/web/views/article.py | 10 | ||||
-rw-r--r-- | newspipe/web/views/bookmark.py | 13 | ||||
-rw-r--r-- | newspipe/web/views/category.py | 8 | ||||
-rw-r--r-- | newspipe/web/views/common.py | 4 | ||||
-rw-r--r-- | newspipe/web/views/feed.py | 18 | ||||
-rw-r--r-- | newspipe/web/views/home.py | 14 | ||||
-rw-r--r-- | newspipe/web/views/icon.py | 5 | ||||
-rw-r--r-- | newspipe/web/views/session_mgmt.py | 12 | ||||
-rw-r--r-- | newspipe/web/views/user.py | 16 | ||||
-rw-r--r-- | newspipe/web/views/views.py | 17 |
17 files changed, 88 insertions, 117 deletions
diff --git a/newspipe/web/views/__init__.py b/newspipe/web/views/__init__.py index a2f7bd1c..7d73ac8c 100644 --- a/newspipe/web/views/__init__.py +++ b/newspipe/web/views/__init__.py @@ -1,37 +1,9 @@ -from web.views.api import v2 -from web.views import views, home, session_mgmt -from web.views.article import article_bp, articles_bp -from web.views.feed import feed_bp, feeds_bp -from web.views.category import category_bp, categories_bp -from web.views.icon import icon_bp -from web.views.admin import admin_bp -from web.views.user import user_bp, users_bp -from web.views.bookmark import bookmark_bp, bookmarks_bp - -__all__ = [ - "views", - "home", - "session_mgmt", - "v2", - "article_bp", - "articles_bp", - "feed_bp", - "feeds_bp", - "category_bp", - "categories_bp", - "icon_bp", - "admin_bp", - "user_bp", - "users_bp", - "bookmark_bp", - "bookmarks_bp", -] - -import conf -from flask import request -from flask import g - - -@g.babel.localeselector -def get_locale(): - return request.accept_languages.best_match(conf.LANGUAGES.keys()) +from newspipe.web.views.api import v2 +from newspipe.web.views import views, home, session_mgmt +from newspipe.web.views.article import article_bp, articles_bp +from newspipe.web.views.feed import feed_bp, feeds_bp +from newspipe.web.views.category import category_bp, categories_bp +from newspipe.web.views.icon import icon_bp +from newspipe.web.views.admin import admin_bp +from newspipe.web.views.user import user_bp, users_bp +from newspipe.web.views.bookmark import bookmark_bp, bookmarks_bp diff --git a/newspipe/web/views/admin.py b/newspipe/web/views/admin.py index fe1b389b..7df683a7 100644 --- a/newspipe/web/views/admin.py +++ b/newspipe/web/views/admin.py @@ -3,10 +3,10 @@ from flask import Blueprint, render_template, redirect, flash, url_for from flask_babel import gettext, format_timedelta from flask_login import login_required, current_user -from lib.utils import redirect_url -from web.views.common import admin_permission -from web.controllers import UserController -from web.forms import InformationMessageForm, UserForm +from newspipe.lib.utils import redirect_url +from newspipe.controllers import UserController +from newspipe.web.views.common import admin_permission +from newspipe.web.forms import InformationMessageForm, UserForm admin_bp = Blueprint("admin", __name__, url_prefix="/admin") diff --git a/newspipe/web/views/api/v2/__init__.py b/newspipe/web/views/api/v2/__init__.py index ef587e72..d367da20 100644 --- a/newspipe/web/views/api/v2/__init__.py +++ b/newspipe/web/views/api/v2/__init__.py @@ -1,3 +1,3 @@ -from web.views.api.v2 import article, feed, category +from newspipe.web.views.api.v2 import article, feed, category __all__ = ["article", "feed", "category"] diff --git a/newspipe/web/views/api/v2/article.py b/newspipe/web/views/api/v2/article.py index 8da6c6dd..1dbf23b2 100644 --- a/newspipe/web/views/api/v2/article.py +++ b/newspipe/web/views/api/v2/article.py @@ -1,12 +1,12 @@ -from conf import API_ROOT +from newspipe.bootstrap import application import dateutil.parser from datetime import datetime from flask import current_app from flask_restful import Api -from web.views.common import api_permission -from web.controllers import ArticleController -from web.views.api.v2.common import ( +from newspipe.web.views.common import api_permission +from newspipe.controllers import ArticleController +from newspipe.web.views.api.v2.common import ( PyAggAbstractResource, PyAggResourceNew, PyAggResourceExisting, @@ -49,7 +49,7 @@ class ArticlesChallenge(PyAggAbstractResource): return result or None, 200 if result else 204 -api = Api(current_app, prefix=API_ROOT) +api = Api(current_app, prefix=application.config['API_ROOT']) api.add_resource(ArticleNewAPI, "/article", endpoint="article_new.json") api.add_resource(ArticleAPI, "/article/<int:obj_id>", endpoint="article.json") diff --git a/newspipe/web/views/api/v2/category.py b/newspipe/web/views/api/v2/category.py index a830624d..5f7ef354 100644 --- a/newspipe/web/views/api/v2/category.py +++ b/newspipe/web/views/api/v2/category.py @@ -1,9 +1,9 @@ -from conf import API_ROOT from flask import current_app from flask_restful import Api -from web.controllers.category import CategoryController -from web.views.api.v2.common import ( +from newspipe.bootstrap import application +from newspipe.controllers.category import CategoryController +from newspipe.web.views.api.v2.common import ( PyAggResourceNew, PyAggResourceExisting, PyAggResourceMulti, @@ -22,7 +22,7 @@ class CategoriesAPI(PyAggResourceMulti): controller_cls = CategoryController -api = Api(current_app, prefix=API_ROOT) +api = Api(current_app, prefix=application.config['API_ROOT']) api.add_resource(CategoryNewAPI, "/category", endpoint="category_new.json") api.add_resource(CategoryAPI, "/category/<int:obj_id>", endpoint="category.json") api.add_resource(CategoriesAPI, "/categories", endpoint="categories.json") diff --git a/newspipe/web/views/api/v2/common.py b/newspipe/web/views/api/v2/common.py index 81248422..3d90bf91 100644 --- a/newspipe/web/views/api/v2/common.py +++ b/newspipe/web/views/api/v2/common.py @@ -26,13 +26,13 @@ from flask import request from flask_restful import Resource, reqparse from flask_login import current_user -from web.views.common import ( +from newspipe.web.views.common import ( admin_permission, api_permission, login_user_bundle, jsonify, ) -from web.controllers import UserController +from newspipe.controllers import UserController logger = logging.getLogger(__name__) diff --git a/newspipe/web/views/api/v2/feed.py b/newspipe/web/views/api/v2/feed.py index 1e4fabf2..1081ed8c 100644 --- a/newspipe/web/views/api/v2/feed.py +++ b/newspipe/web/views/api/v2/feed.py @@ -1,11 +1,11 @@ -from conf import API_ROOT from flask import current_app from flask_restful import Api -from web.views.common import api_permission -from web.controllers.feed import FeedController, DEFAULT_MAX_ERROR, DEFAULT_LIMIT +from newspipe.bootstrap import application +from newspipe.web.views.common import api_permission +from newspipe.controllers.feed import FeedController, DEFAULT_MAX_ERROR, DEFAULT_LIMIT -from web.views.api.v2.common import ( +from newspipe.web.views.api.v2.common import ( PyAggAbstractResource, PyAggResourceNew, PyAggResourceExisting, @@ -39,7 +39,7 @@ class FetchableFeedAPI(PyAggAbstractResource): return result or None, 200 if result else 204 -api = Api(current_app, prefix=API_ROOT) +api = Api(current_app, prefix=application.config['API_ROOT']) api.add_resource(FeedNewAPI, "/feed", endpoint="feed_new.json") api.add_resource(FeedAPI, "/feed/<int:obj_id>", endpoint="feed.json") diff --git a/newspipe/web/views/article.py b/newspipe/web/views/article.py index c0c6f346..a49859ca 100644 --- a/newspipe/web/views/article.py +++ b/newspipe/web/views/article.py @@ -14,11 +14,11 @@ from flask_babel import gettext from flask_login import login_required, current_user -from bootstrap import db -from lib.utils import clear_string, redirect_url -from lib.data import export_json -from web.controllers import ArticleController, UserController, CategoryController -from web.lib.view_utils import etag_match +from newspipe.bootstrap import db +from newspipe.lib.utils import clear_string, redirect_url +from newspipe.lib.data import export_json +from newspipe.controllers import ArticleController, UserController, CategoryController +from newspipe.web.lib.view_utils import etag_match articles_bp = Blueprint("articles", __name__, url_prefix="/articles") article_bp = Blueprint("article", __name__, url_prefix="/article") diff --git a/newspipe/web/views/bookmark.py b/newspipe/web/views/bookmark.py index 2577f747..ea49b3c8 100644 --- a/newspipe/web/views/bookmark.py +++ b/newspipe/web/views/bookmark.py @@ -44,13 +44,12 @@ from flask_login import login_required, current_user from flask_paginate import Pagination, get_page_args from sqlalchemy import desc -import conf -from lib.utils import redirect_url -from lib.data import import_pinboard_json, export_bookmarks -from bootstrap import db -from web.forms import BookmarkForm -from web.controllers import BookmarkController, BookmarkTagController -from web.models import BookmarkTag +from newspipe.lib.utils import redirect_url +from newspipe.lib.data import import_pinboard_json, export_bookmarks +from newspipe.bootstrap import db +from newspipe.web.forms import BookmarkForm +from newspipe.controllers import BookmarkController, BookmarkTagController +from newspipe.models import BookmarkTag logger = logging.getLogger(__name__) bookmarks_bp = Blueprint("bookmarks", __name__, url_prefix="/bookmarks") diff --git a/newspipe/web/views/category.py b/newspipe/web/views/category.py index 1c897058..9f1a7e83 100644 --- a/newspipe/web/views/category.py +++ b/newspipe/web/views/category.py @@ -2,10 +2,10 @@ from flask import Blueprint, render_template, flash, redirect, url_for from flask_babel import gettext from flask_login import login_required, current_user -from web.forms import CategoryForm -from lib.utils import redirect_url -from web.lib.view_utils import etag_match -from web.controllers import ArticleController, FeedController, CategoryController +from newspipe.web.forms import CategoryForm +from newspipe.lib.utils import redirect_url +from newspipe.web.lib.view_utils import etag_match +from newspipe.controllers import ArticleController, FeedController, CategoryController categories_bp = Blueprint("categories", __name__, url_prefix="/categories") category_bp = Blueprint("category", __name__, url_prefix="/category") diff --git a/newspipe/web/views/common.py b/newspipe/web/views/common.py index c2d8e2df..8d9ecfa9 100644 --- a/newspipe/web/views/common.py +++ b/newspipe/web/views/common.py @@ -10,8 +10,8 @@ from flask_principal import ( session_identity_loader, identity_changed, ) -from web.controllers import UserController -from lib.utils import default_handler +from newspipe.controllers import UserController +from newspipe.lib.utils import default_handler admin_role = RoleNeed("admin") api_role = RoleNeed("api") diff --git a/newspipe/web/views/feed.py b/newspipe/web/views/feed.py index 592e3cbf..0be30668 100644 --- a/newspipe/web/views/feed.py +++ b/newspipe/web/views/feed.py @@ -17,12 +17,12 @@ 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 -from lib.feed_utils import construct_feed_from -from web.lib.view_utils import etag_match -from web.forms import AddFeedForm -from web.controllers import ( +from newspipe.bootstrap import application +from newspipe.lib import misc_utils, utils +from newspipe.lib.feed_utils import construct_feed_from +from newspipe.web.lib.view_utils import etag_match +from newspipe.web.forms import AddFeedForm +from newspipe.controllers import ( UserController, CategoryController, FeedController, @@ -179,7 +179,7 @@ def bookmarklet(): ) feed = feed_contr.create(**feed) flash(gettext("Feed was successfully created."), "success") - if feed.enabled and conf.CRAWLING_METHOD == "default": + if feed.enabled and application.confg['CRAWLING_METHOD'] == "default": misc_utils.fetch(current_user.id, feed.id) flash(gettext("Downloading articles for the new feed..."), "info") return redirect(url_for("feed.form", feed_id=feed.id)) @@ -286,7 +286,7 @@ def process_form(feed_id=None): "success", ) - if conf.CRAWLING_METHOD == "default": + if application.confg['CRAWLING_METHOD'] == "default": misc_utils.fetch(current_user.id, new_feed.id) flash(gettext("Downloading articles for the new feed..."), "info") @@ -335,7 +335,7 @@ def export(): if not include_private: filter["private"] = False if not include_exceeded_error_count: - filter["error_count__lt"] = conf.DEFAULT_MAX_ERROR + filter["error_count__lt"] = application.confg['DEFAULT_MAX_ERROR'] user = UserController(current_user.id).get(id=current_user.id) feeds = FeedController(current_user.id).read(**filter) diff --git a/newspipe/web/views/home.py b/newspipe/web/views/home.py index 1cfa3601..66ce87ea 100644 --- a/newspipe/web/views/home.py +++ b/newspipe/web/views/home.py @@ -7,13 +7,13 @@ from flask_login import login_required, current_user from flask_babel import gettext, get_locale from babel.dates import format_datetime, format_timedelta -import conf -from lib.utils import redirect_url -from lib import misc_utils -from web.lib.view_utils import etag_match -from web.views.common import jsonify +from newspipe.bootstrap import application +from newspipe.lib.utils import redirect_url +from newspipe.lib import misc_utils +from newspipe.web.lib.view_utils import etag_match +from newspipe.web.views.common import jsonify -from web.controllers import FeedController, ArticleController, CategoryController +from newspipe.controllers import FeedController, ArticleController, CategoryController localize = pytz.utc.localize logger = logging.getLogger(__name__) @@ -181,7 +181,7 @@ def fetch(feed_id=None): Triggers the download of news. News are downloaded in a separated process. """ - if conf.CRAWLING_METHOD == "default" and current_user.is_admin: + if application.config['CRAWLING_METHOD'] == "default" and current_user.is_admin: misc_utils.fetch(current_user.id, feed_id) flash(gettext("Downloading articles..."), "info") else: diff --git a/newspipe/web/views/icon.py b/newspipe/web/views/icon.py index e1de6402..4cdcd4b0 100644 --- a/newspipe/web/views/icon.py +++ b/newspipe/web/views/icon.py @@ -1,7 +1,8 @@ import base64 from flask import Blueprint, Response, request -from web.controllers import IconController -from web.lib.view_utils import etag_match + +from newspipe.controllers import IconController +from newspipe.web.lib.view_utils import etag_match icon_bp = Blueprint("icon", __name__, url_prefix="/icon") diff --git a/newspipe/web/views/session_mgmt.py b/newspipe/web/views/session_mgmt.py index 809825d3..9bdb89cb 100644 --- a/newspipe/web/views/session_mgmt.py +++ b/newspipe/web/views/session_mgmt.py @@ -24,11 +24,11 @@ from flask_principal import ( session_identity_loader, ) -import conf -from web.views.common import admin_role, api_role, login_user_bundle -from web.controllers import UserController -from web.forms import SignupForm, SigninForm -from notifications import notifications +from newspipe.bootstrap import application +from newspipe.web.views.common import admin_role, api_role, login_user_bundle +from newspipe.controllers import UserController +from newspipe.web.forms import SignupForm, SigninForm +from newspipe.notifications import notifications Principal(current_app) # Create a permission with a single Need, in this case a RoleNeed. @@ -99,7 +99,7 @@ def logout(): @current_app.route("/signup", methods=["GET", "POST"]) def signup(): - if not conf.SELF_REGISTRATION: + if not application.config['SELF_REGISTRATION']: flash(gettext("Self-registration is disabled."), "warning") return redirect(url_for("home")) if current_user.is_authenticated: diff --git a/newspipe/web/views/user.py b/newspipe/web/views/user.py index 10974947..39eefb4c 100644 --- a/newspipe/web/views/user.py +++ b/newspipe/web/views/user.py @@ -6,12 +6,12 @@ from flask_babel import gettext from flask_login import login_required, current_user from flask_paginate import Pagination, get_page_args -import conf -from notifications import notifications -from lib import misc_utils -from lib.data import import_opml, import_json -from web.lib.user_utils import confirm_token -from web.controllers import ( +from newspipe.bootstrap import application +from newspipe.notifications import notifications +from newspipe.lib import misc_utils +from newspipe.lib.data import import_opml, import_json +from newspipe.web.lib.user_utils import confirm_token +from newspipe.controllers import ( UserController, FeedController, ArticleController, @@ -19,7 +19,7 @@ from web.controllers import ( BookmarkController, ) -from web.forms import ProfileForm +from newspipe.web.forms import ProfileForm users_bp = Blueprint("users", __name__, url_prefix="/users") user_bp = Blueprint("user", __name__, url_prefix="/user") @@ -115,7 +115,7 @@ def management(): else: try: nb = import_opml(current_user.nickname, data.read()) - if conf.CRAWLING_METHOD == "classic": + if application.config['CRAWLING_METHOD'] == "classic": misc_utils.fetch(current_user.id, None) flash(str(nb) + " " + gettext("feeds imported."), "success") flash(gettext("Downloading articles..."), "info") diff --git a/newspipe/web/views/views.py b/newspipe/web/views/views.py index e08270cd..6aa6ce54 100644 --- a/newspipe/web/views/views.py +++ b/newspipe/web/views/views.py @@ -6,11 +6,10 @@ from flask import request, render_template, flash, url_for, redirect, current_ap from flask_babel import gettext from sqlalchemy import desc -import conf -from web import __version__ -from conf import API_ROOT, ADMIN_EMAIL -from web.controllers import FeedController, UserController -from web.lib.view_utils import etag_match +from newspipe.bootstrap import application +from newspipe.web import __version__ +from newspipe.controllers import FeedController, UserController +from newspipe.web.lib.view_utils import etag_match logger = logging.getLogger(__name__) @@ -25,7 +24,7 @@ def authentication_required(error): @current_app.errorhandler(403) def authentication_failed(error): - if API_ROOT in request.url: + if application.conf['API_ROOT'] in request.url: return error flash(gettext("Forbidden."), "danger") return redirect(url_for("login")) @@ -71,7 +70,7 @@ def popular(): filters = {} filters["created_date__gt"] = not_added_before filters["private"] = False - filters["error_count__lt"] = conf.DEFAULT_MAX_ERROR + filters["error_count__lt"] = application.config['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) @@ -80,7 +79,7 @@ def popular(): @current_app.route("/about", methods=["GET"]) @etag_match def about(): - return render_template("about.html", contact=ADMIN_EMAIL) + return render_template("about.html", contact=application.config['ADMIN_EMAIL']) @current_app.route("/about/more", methods=["GET"]) @@ -102,7 +101,7 @@ def about_more(): "about_more.html", newspipe_version=newspipe_version, version_url=version_url, - registration=[conf.SELF_REGISTRATION and "Open" or "Closed"][0], + registration=[application.config['SELF_REGISTRATION'] and "Open" or "Closed"][0], python_version="{}.{}.{}".format(*sys.version_info[:3]), nb_users=UserController().read().count(), ) |