From 27d52720326df19815179f04a1bf3cea671ab5cf Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 25 Apr 2024 12:07:30 +0300 Subject: [PATCH] fmt --- pyproject.toml | 6 ++++++ resolvers/__init__.py | 14 ++------------ resolvers/notifier.py | 7 +------ resolvers/reader.py | 9 ++++++--- resolvers/stat.py | 7 ++----- services/viewed.py | 7 +------ 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5e198f6c..a0bc2c7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,3 +35,9 @@ build-backend = "poetry.core.masonry.api" [tool.pyright] venvPath = "." venv = ".venv" + +[tool.isort] +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +line_length = 120 diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 41e40d03..9526d9db 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -12,12 +12,7 @@ from resolvers.author import ( ) from resolvers.community import get_communities_all, get_community from resolvers.editor import create_shout, delete_shout, update_shout -from resolvers.follower import ( - follow, - get_shout_followers, - get_topic_followers, - unfollow, -) +from resolvers.follower import follow, get_shout_followers, get_topic_followers, unfollow from resolvers.notifier import ( load_notifications, notification_mark_seen, @@ -41,12 +36,7 @@ from resolvers.reader import ( load_shouts_search, load_shouts_unrated, ) -from resolvers.topic import ( - get_topic, - get_topics_all, - get_topics_by_author, - get_topics_by_community, -) +from resolvers.topic import get_topic, get_topics_all, get_topics_by_author, get_topics_by_community from services.triggers import events_register events_register() diff --git a/resolvers/notifier.py b/resolvers/notifier.py index 8ce824e3..8a3b9a91 100644 --- a/resolvers/notifier.py +++ b/resolvers/notifier.py @@ -8,12 +8,7 @@ from sqlalchemy.orm import aliased from sqlalchemy.sql import not_ from orm.author import Author -from orm.notification import ( - Notification, - NotificationAction, - NotificationEntity, - NotificationSeen, -) +from orm.notification import Notification, NotificationAction, NotificationEntity, NotificationSeen from orm.shout import Shout from services.auth import login_required from services.db import local_session diff --git a/resolvers/reader.py b/resolvers/reader.py index fa130bd2..134b3a26 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -53,9 +53,12 @@ def apply_filters(q, filters, author_id=None): if filters.get("reacted"): q.join(Reaction, Reaction.created_by == author_id) - by_featured = filters.get("featured") - if by_featured: - q = q.filter(Shout.featured_at.is_not(None)) + by_featured = filters.get("featured", "not set") + if isinstance(by_featured, bool): + if by_featured: + q = q.filter(Shout.featured_at.is_not(None)) + else: + q = q.filter(Shout.featured_at.is_(None)) by_layouts = filters.get("layouts") if by_layouts: q = q.filter(Shout.layout.in_(by_layouts)) diff --git a/resolvers/stat.py b/resolvers/stat.py index f8670fed..d16905fc 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -16,9 +16,7 @@ def add_topic_stat_columns(q): func.count(distinct(aliased_shout.shout)).label("shouts_stat") ) aliased_follower = aliased(TopicFollower) - q = q.outerjoin( - aliased_follower, aliased_follower.topic == Topic.id - ).add_columns( + q = q.outerjoin(aliased_follower, aliased_follower.topic == Topic.id).add_columns( func.count(distinct(aliased_follower.follower)).label("followers_stat") ) @@ -27,8 +25,6 @@ def add_topic_stat_columns(q): return q - - def add_author_stat_columns(q): aliased_shout = aliased(ShoutAuthor) q = q.outerjoin(aliased_shout).add_columns( @@ -116,6 +112,7 @@ def get_topic_comments_stat(topic_id: int): result = local_session().execute(q).first() return result[0] if result else 0 + def get_author_shouts_stat(author_id: int): aliased_shout_author = aliased(ShoutAuthor) q = select(func.count(distinct(aliased_shout_author.shout))).filter( diff --git a/services/viewed.py b/services/viewed.py index abf0f22e..4e4ee4b5 100644 --- a/services/viewed.py +++ b/services/viewed.py @@ -7,12 +7,7 @@ from typing import Dict # ga from google.analytics.data_v1beta import BetaAnalyticsDataClient -from google.analytics.data_v1beta.types import ( - DateRange, - Dimension, - Metric, - RunReportRequest, -) +from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest from orm.author import Author from orm.shout import Shout, ShoutAuthor, ShoutTopic