~roshless/nnrss

842e83f2cceb5d67ff16acbd27841912abd46256 — Roshless 1 year, 3 months ago bad05e4 1.2.0
web_interface: show feeds from category
3 files changed, 38 insertions(+), 2 deletions(-)

M nnrss/database.py
M nnrss/templates/feed_list.html
M nnrss/views.py
M nnrss/database.py => nnrss/database.py +14 -0
@@ 211,6 211,17 @@ class RssHandler:
            session.add(Category(name=category_input))
            return session.query(Category).filter_by(name=category_input)

    def __get_all_categories(self, username: str) -> List[Category]:
        with self.__session_scope() as session:
            return (
                session.query(Category)
                .join(Feed)
                .join(User)
                .filter(User.username == username)
                .filter(Category.feeds.any())
                .order_by(Category.name)
            )

    def __add_category(self, category_input: str):
        with self.__session_scope() as session:
            session.add(Category(name=category_input))


@@ 416,6 427,9 @@ class RssHandler:
    def get_or_add_category(self, category: str) -> Category:
        return self.__get_category(category).first()

    def get_all_categories(self, username: str) -> List[Category]:
        return self.__get_all_categories(username).all()

    def set_read_entry(
        self, feed_id: int, entry_id: int, username: str
    ) -> Tuple[bool, Optional[str]]:

M nnrss/templates/feed_list.html => nnrss/templates/feed_list.html +20 -1
@@ 1,14 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 %}Feed list{% endblock %}</h2>
{% endblock %}

{% block subtitle %}
<h4>Logged in as {{ username }}</h4>
{% 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 feeds %}

M nnrss/views.py => nnrss/views.py +4 -1
@@ 33,12 33,15 @@ def index():
    handler = RssHandler()
    if category:
        feeds = handler.get_feeds_from_category(session["logged_in"], category)
        categories = None
    else:
        feeds = handler.get_feeds(session["logged_in"])
        categories = handler.get_all_categories(session["logged_in"])
    return render_template(
        "feed_list.html",
        feeds=feeds,
        username=session["logged_in"],
        categories=categories,
        category_name=category,
    )