~roshless/nnrss

0ac5d412d1ed3db8e1d17e90bd770b0424d21359 — Roshless 4 months ago eaa309f
formatting using black with iosort

also config change for it
6 files changed, 73 insertions(+), 47 deletions(-)

M nnrss/__init__.py
M nnrss/database.py
M nnrss/forms.py
M nnrss/models.py
M nnrss/views.py
M setup.cfg
M nnrss/__init__.py => nnrss/__init__.py +2 -1
@@ 20,7 20,8 @@ def create_app():
    app.secret_key = ACCOUNT.get_secret_key()

    app.config.update(
        SESSION_COOKIE_HTTPONLY=True, SESSION_COOKIE_SAMESITE="Lax",
        SESSION_COOKIE_HTTPONLY=True,
        SESSION_COOKIE_SAMESITE="Lax",
    )

    @app.teardown_appcontext

M nnrss/database.py => nnrss/database.py +8 -32
@@ 103,11 103,7 @@ class RssHandler:
            parsed_entries = self.__parse_feed(feed.rss_link, only_entries=True)
            if parsed_entries is None:
                return False
            new_entries = [
                x
                for x in parsed_entries
                if x not in set(feed.entries)
            ]
            new_entries = [x for x in parsed_entries if x not in set(feed.entries)]
            feed.entries.extend(new_entries)
            return True



@@ 122,9 118,7 @@ class RssHandler:
            if not hasattr(feed, "rss_link"):
                return False
            parsed_entries = self.__parse_feed(feed.rss_link, only_entries=True)
            new_entries = [
                x for x in parsed_entries if x not in set(feed.entries)
            ]
            new_entries = [x for x in parsed_entries if x not in set(feed.entries)]
            feed.updated_date = dt.utcnow()
            feed.entries.extend(new_entries)
            return True


@@ 165,7 159,7 @@ class RssHandler:
                .join(Feed)
                .join(User)
                .filter(FeedEntry.id_feed == feed_id)
                .filter(FeedEntry.is_read == False)
                .filter(FeedEntry.is_read is False)
                .filter(User.username == username)
                .order_by(FeedEntry.date.desc())
            )


@@ 176,7 170,7 @@ class RssHandler:
                session.query(FeedEntry)
                .join(Feed)
                .join(User)
                .filter(FeedEntry.is_read == False)
                .filter(FeedEntry.is_read is False)
                .filter(User.username == username)
                .order_by(FeedEntry.date.asc())
            )


@@ 188,7 182,7 @@ class RssHandler:
                .join(Feed)
                .join(User)
                .join(Category)
                .filter(FeedEntry.is_read == False)
                .filter(FeedEntry.is_read is False)
                .filter(Category.name == category)
                .filter(User.username == username)
                .order_by(FeedEntry.date.asc())


@@ 289,11 283,11 @@ class RssHandler:
                content = entry.summary

            try:
                date=dt.fromtimestamp(mktime(entry.published_parsed))
                date = dt.fromtimestamp(mktime(entry.published_parsed))
            except AttributeError:
                date=dt.fromtimestamp(mktime(entry.updated_parsed))
                date = dt.fromtimestamp(mktime(entry.updated_parsed))
            except ValueError:
                date=dt.fromtimestamp(1)
                date = dt.fromtimestamp(1)

            feed_entries_list.append(
                FeedEntry(


@@ 475,21 469,3 @@ class RssHandler:
        if username is None:
            return self.__set_read_status(feed_id, entry_id)
        return self.__set_read_status_auth(feed_id, entry_id, username)

    def set_read_entry(
        self, feed_id: int, entry_id: int, username: str
    ) -> Tuple[bool, Optional[str]]:
        """Won't work with wrong coresponding ids."""
        if username is None:
            return self.__set_read_status(feed_id, entry_id)
        return self.__set_read_status_auth(feed_id, entry_id, username)
        return self.__set_read_status_auth(feed_id, entry_id, username)

    def set_read_entry(
        self, feed_id: int, entry_id: int, username: str
    ) -> Tuple[bool, Optional[str]]:
        """Won't work with wrong coresponding ids."""
        if username is None:
            return self.__set_read_status(feed_id, entry_id)
        return self.__set_read_status_auth(feed_id, entry_id, username)
        return self.__set_read_status_auth(feed_id, entry_id, username)

M nnrss/forms.py => nnrss/forms.py +9 -2
@@ 1,6 1,13 @@
"""Module containing wtforms definitions"""
from wtforms import (FileField, Form, IntegerField, PasswordField, StringField,
                     SubmitField, validators)
from wtforms import (
    FileField,
    Form,
    IntegerField,
    PasswordField,
    StringField,
    SubmitField,
    validators,
)


def username_validator():

M nnrss/models.py => nnrss/models.py +12 -3
@@ 1,8 1,15 @@
import datetime
import os

from sqlalchemy import (Boolean, Column, DateTime, ForeignKey, Integer, String,
                        create_engine)
from sqlalchemy import (
    Boolean,
    Column,
    DateTime,
    ForeignKey,
    Integer,
    String,
    create_engine,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, scoped_session, sessionmaker



@@ 48,7 55,9 @@ class Feed(BASE):
    title = Column(String)
    link = Column(String)
    rss_link = Column(String)
    entries = relationship("FeedEntry", back_populates="feed", cascade="all, delete-orphan")
    entries = relationship(
        "FeedEntry", back_populates="feed", cascade="all, delete-orphan"
    )
    updated_date = Column(DateTime, default=datetime.datetime.utcnow)



M nnrss/views.py => nnrss/views.py +35 -9
@@ 1,8 1,7 @@
"""Module containing main views for web client"""
import datetime as dt

from flask import (Blueprint, Response, flash, render_template, request,
                   session, url_for)
from flask import Blueprint, Response, flash, render_template, request, session, url_for
from werkzeug.datastructures import CombinedMultiDict
from werkzeug.exceptions import abort
from werkzeug.security import check_password_hash, generate_password_hash


@@ 10,10 9,20 @@ from werkzeug.utils import redirect

from nnrss.background_update import BACKGROUND_TASK
from nnrss.database import RssHandler
from nnrss.decorators import (admin_required, guest_required, login_required,
                              registration_enabled)
from nnrss.forms import (AddFeedForm, ExportForm, ImportForm, LoginForm,
                         RegistrationForm, SettingsForm)
from nnrss.decorators import (
    admin_required,
    guest_required,
    login_required,
    registration_enabled,
)
from nnrss.forms import (
    AddFeedForm,
    ExportForm,
    ImportForm,
    LoginForm,
    RegistrationForm,
    SettingsForm,
)
from nnrss.models import User
from nnrss.opml import OPMLWriter
from nnrss.thread_import import ImportThread


@@ 44,6 53,7 @@ def index():
        categories=categories,
    )


@DEFAULT_WEB.route("/list")
@login_required
def feed_list():


@@ 62,6 72,7 @@ def feed_list():
        category_name=category,
    )


@DEFAULT_WEB.route("/add", methods=["GET", "POST"])
@login_required
def add_feed():


@@ 90,7 101,9 @@ def view_feed_entries(feed_id=None):
    entries = handler.get_entries_by_feed_id(feed_id, session["logged_in"])
    selected_feed = handler.get_feed_without_details(feed_id, session["logged_in"])
    return render_template(
        "entries_list.html", entries=entries.paginate(page=page), feed=selected_feed,
        "entries_list.html",
        entries=entries.paginate(page=page),
        feed=selected_feed,
    )




@@ 106,7 119,9 @@ def view_feed_entries_unread(feed_id=None):
    entries = handler.get_unread_entries_by_feed_id(feed_id, session["logged_in"])
    selected_feed = handler.get_feed_without_details(feed_id, session["logged_in"])
    return render_template(
        "entries_list_unread.html", entries=entries.paginate(page=page), feed=selected_feed,
        "entries_list_unread.html",
        entries=entries.paginate(page=page),
        feed=selected_feed,
    )




@@ 217,7 232,9 @@ def settings():
    user_prefs = handler.get_user(session["logged_in"])
    form = SettingsForm(request.form, user_prefs)
    if request.method == "POST" and form.validate():
        user_prefs.password = generate_password_hash(form.password.data, method="pbkdf2:sha512")
        user_prefs.password = generate_password_hash(
            form.password.data, method="pbkdf2:sha512"
        )
        user_prefs.api_key = form.api_key.data
        user_prefs.update_interval = form.update_interval.data
        handler.add_user(user_prefs)


@@ 281,3 298,12 @@ def export_feeds():
            },
        )
    return render_template("export_feeds.html", form=form)
            writer.get_exported_feeds(),
            mimetype="text/xml",
            headers={
                "Content-Disposition": "attachment;filename=feeds-"
                + str(dt.date.today())
                + ".opml"
            },
        )
    return render_template("export_feeds.html", form=form)

M setup.cfg => setup.cfg +7 -0
@@ 2,3 2,10 @@
max-line-length = 88
ignore = E203, W503

[isort]
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
ensure_newline_before_comments = True
line_length = 88