From 0b185c1c2dbeaff3ed96911cfbbebc4e3bc9c1d9 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 24 Apr 2024 10:42:33 +0300 Subject: [PATCH] fmt --- resolvers/__init__.py | 64 +++++++++++++++++++++++++++++++------------ resolvers/author.py | 3 +- resolvers/follower.py | 3 +- resolvers/notifier.py | 8 ++++-- resolvers/reaction.py | 3 +- resolvers/reader.py | 3 +- resolvers/stat.py | 13 ++++++--- services/db.py | 3 +- services/viewed.py | 8 ++++-- 9 files changed, 72 insertions(+), 36 deletions(-) diff --git a/resolvers/__init__.py b/resolvers/__init__.py index dd22ecb7..41e40d03 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -1,24 +1,52 @@ -from resolvers.author import (get_author, get_author_followers, - get_author_follows, get_author_follows_authors, - get_author_follows_topics, get_author_id, - get_authors_all, load_authors_by, search_authors, - update_author) +from resolvers.author import ( + get_author, + get_author_followers, + get_author_follows, + get_author_follows_authors, + get_author_follows_topics, + get_author_id, + get_authors_all, + load_authors_by, + search_authors, + update_author, +) 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.notifier import (load_notifications, notification_mark_seen, - notifications_seen_after, - notifications_seen_thread) +from resolvers.follower import ( + follow, + get_shout_followers, + get_topic_followers, + unfollow, +) +from resolvers.notifier import ( + load_notifications, + notification_mark_seen, + notifications_seen_after, + notifications_seen_thread, +) from resolvers.rating import rate_author -from resolvers.reaction import (create_reaction, delete_reaction, - load_reactions_by, load_shouts_followed, - update_reaction) -from resolvers.reader import (get_shout, load_shouts_by, load_shouts_feed, - load_shouts_random_top, load_shouts_random_topic, - 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.reaction import ( + create_reaction, + delete_reaction, + load_reactions_by, + load_shouts_followed, + update_reaction, +) +from resolvers.reader import ( + get_shout, + load_shouts_by, + load_shouts_feed, + load_shouts_random_top, + load_shouts_random_topic, + load_shouts_search, + load_shouts_unrated, +) +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/author.py b/resolvers/author.py index 8ac59a54..c75ee5a0 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -8,8 +8,7 @@ from sqlalchemy_searchable import search from orm.author import Author, AuthorFollower from orm.shout import ShoutAuthor, ShoutTopic from orm.topic import Topic -from resolvers.stat import (author_follows_authors, author_follows_topics, - get_with_stat) +from resolvers.stat import author_follows_authors, author_follows_topics, get_with_stat from services.auth import login_required from services.cache import cache_author, cache_follower from services.db import local_session diff --git a/resolvers/follower.py b/resolvers/follower.py index eb0d4e09..b29f75ab 100644 --- a/resolvers/follower.py +++ b/resolvers/follower.py @@ -11,8 +11,7 @@ from orm.community import Community from orm.reaction import Reaction from orm.shout import Shout, ShoutReactionsFollower from orm.topic import Topic, TopicFollower -from resolvers.stat import (author_follows_authors, author_follows_topics, - get_with_stat) +from resolvers.stat import author_follows_authors, author_follows_topics, get_with_stat from services.auth import login_required from services.cache import DEFAULT_FOLLOWS, cache_follower from services.db import local_session diff --git a/resolvers/notifier.py b/resolvers/notifier.py index 7b9346f8..8ce824e3 100644 --- a/resolvers/notifier.py +++ b/resolvers/notifier.py @@ -8,8 +8,12 @@ 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/reaction.py b/resolvers/reaction.py index 31dd51b7..5abc152c 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -6,8 +6,7 @@ from sqlalchemy.orm import aliased, joinedload from sqlalchemy.sql import union from orm.author import Author -from orm.rating import (PROPOSAL_REACTIONS, RATING_REACTIONS, is_negative, - is_positive) +from orm.rating import PROPOSAL_REACTIONS, RATING_REACTIONS, is_negative, is_positive from orm.reaction import Reaction, ReactionKind from orm.shout import Shout from resolvers.editor import handle_proposing diff --git a/resolvers/reader.py b/resolvers/reader.py index 8090cd15..fa130bd2 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -1,7 +1,6 @@ from sqlalchemy import bindparam, distinct, or_, text from sqlalchemy.orm import aliased, joinedload -from sqlalchemy.sql.expression import (and_, asc, case, desc, func, nulls_last, - select) +from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select from orm.author import Author, AuthorFollower from orm.reaction import Reaction, ReactionKind diff --git a/resolvers/stat.py b/resolvers/stat.py index 3fa79b2d..2f6f8a82 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -16,7 +16,8 @@ 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.follower == Author.id + q = q.outerjoin( + aliased_follower, aliased_follower.follower == Author.id ).add_columns( func.count(distinct(aliased_follower.follower)).label("followers_stat") ) @@ -32,7 +33,8 @@ def add_author_stat_columns(q): func.count(distinct(aliased_shout.shout)).label("shouts_stat") ) aliased_follower = aliased(AuthorFollower) - q = q.outerjoin(aliased_follower, aliased_follower.follower == Author.id + q = q.outerjoin( + aliased_follower, aliased_follower.follower == Author.id ).add_columns( func.count(distinct(aliased_follower.follower)).label("followers_stat") ) @@ -41,6 +43,7 @@ def add_author_stat_columns(q): return q + def get_topic_shouts_stat(topic_id: int): q = ( select(func.count(distinct(ShoutTopic.shout))) @@ -150,7 +153,7 @@ def get_author_comments_stat(author_id: int): select( Author.id, func.coalesce(func.count(Reaction.id)).label("comments_count") ) - .select_from(Author) # явно указываем левый элемент join'а + .select_from(Author) # явно указываем левый элемент join'а .outerjoin( Reaction, and_( @@ -174,7 +177,9 @@ def get_with_stat(q): is_author = f"{q}".lower().startswith("select author") # is_topic = f"{q}".lower().startswith("select topic") result = [] - add_stat_handler = add_author_stat_columns if is_author else add_topic_stat_columns + add_stat_handler = ( + add_author_stat_columns if is_author else add_topic_stat_columns + ) with local_session() as session: result = session.execute(add_stat_handler(q)) diff --git a/services/db.py b/services/db.py index 048333b7..7030f3bb 100644 --- a/services/db.py +++ b/services/db.py @@ -5,8 +5,7 @@ import traceback import warnings from typing import Any, Callable, Dict, TypeVar -from sqlalchemy import (JSON, Column, Engine, Integer, create_engine, event, - exc, inspect) +from sqlalchemy import JSON, Column, Engine, Integer, create_engine, event, exc, inspect from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session, configure_mappers from sqlalchemy.sql.schema import Table diff --git a/services/viewed.py b/services/viewed.py index c6abfe0f..abf0f22e 100644 --- a/services/viewed.py +++ b/services/viewed.py @@ -7,8 +7,12 @@ 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