~roshless/nnrss

4699b5ecfda7879244ca394253b75022ddd2f1dc — Roshless 5 months ago acd674e 1.3.0
feat: categories to unread entries list
3 files changed, 50 insertions(+), 4 deletions(-)

M nnrss/database.py
M nnrss/templates/unread_entries.html
M nnrss/views.py
M nnrss/database.py => nnrss/database.py +19 -3
@@ 183,6 183,19 @@ class RssHandler:
                .order_by(FeedEntry.date.asc())
            )

    def __get_unread_entries_by_category(self, username, category):
        with self.__session_scope() as session:
            return (
                session.query(FeedEntry)
                .join(Feed)
                .join(User)
                .join(Category)
                .filter(FeedEntry.is_read == False)
                .filter(Category.name == category)
                .filter(User.username == username)
                .order_by(FeedEntry.date.asc())
            )

    def __remove_feed(self, feed_id):
        with self.__session_scope() as session:
            author = session.query(Feed).filter_by(id=feed_id).first()


@@ 428,10 441,13 @@ class RssHandler:
            raise NotImplementedError
        return self.__get_unread_entries_by_id_and_username(feed_id, username)

    def get_unread_entries(self, username: str = None) -> Query:
        if username is None:
    def get_unread_entries(self, username: str = None, category: str = None) -> Query:
        if not username:
            raise NotImplementedError
        return self.__get_unread_entries(username)
        if category:
            return self.__get_unread_entries_by_category(username, category)
        else:
            return self.__get_unread_entries(username)

    def update_feed(self, feed_id: int, username: str = None) -> bool:
        """Get new entries for feed."""

M nnrss/templates/unread_entries.html => nnrss/templates/unread_entries.html +23 -0
@@ 1,10 1,33 @@
{% extends 'base.html' %}

{% block more_css %}
<link rel="stylesheet" href="{{ url_for('static', filename='checkbox_hide.css') }}">
{% endblock %}

{% block header %}
<h2>{% block title %}Unread entries{% endblock %}</h2>
{% endblock %}

{% block subtitle %}
{% if category_name %}
    <h4>Category: {{ category_name }}</h4>
{% else %}
    <h4>All feeds</h4>
{% endif %}
{% endblock %}

{% block content %}
{% if categories %}
<div class="col-md-8 text-center">
    <input id="checkbox_categories" class="form-check-input mb-2" type="checkbox">
    <label class="form-check-label" for="checkbox_categories">Show categories</label>
    <div id="hide" class="d-flex flex-wrap justify-content-center">
	{% for category in categories %}
	    <a class="p-2 m-1 bg-light rounded" href="?category={{ category.name }}">{{ category.name }}</a>
	{% endfor %}
    </div>
</div>
{% endif %}
<div class="col-md-10">
    <ul class="list-group list-group-flush">
	{% for item in entries %}

M nnrss/views.py => nnrss/views.py +8 -1
@@ 31,10 31,17 @@ def page_not_found(error):
def index():
    category = request.args.get("category", None)
    handler = RssHandler()
    entries = handler.get_unread_entries(session["logged_in"])
    if category:
        entries = handler.get_unread_entries(session["logged_in"], category)
        categories = None
    else:
        entries = handler.get_unread_entries(session["logged_in"])
        categories = handler.get_all_categories(session["logged_in"])
    return render_template(
        "unread_entries.html",
        entries=entries,
        category_name=category,
        categories=categories,
    )

@DEFAULT_WEB.route("/list")