~cedric/newspipe

b8635353572799956ae15ae1d923a481986f5fce — Cédric Bonhomme 1 year, 6 months ago 9b1d18d
improved home page loading
M newspipe/web/controllers/article.py => newspipe/web/controllers/article.py +3 -0
@@ 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())

M newspipe/web/models/article.py => newspipe/web/models/article.py +1 -1
@@ 86,7 86,7 @@ class Article(db.Model, RightMixin):
            "date",
            "retrieved_date",
            "user_id",
            "tags"
            "tags",
        }

    @staticmethod

M newspipe/web/templates/home.html => newspipe/web/templates/home.html +3 -1
@@ 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>

M newspipe/web/views/article.py => newspipe/web/views/article.py +1 -3
@@ 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):
    """

M newspipe/web/views/home.py => newspipe/web/views/home.py +39 -16
@@ 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 = {}