mirror of
https://github.com/zulip/zulip.git
synced 2025-10-27 18:13:58 +00:00
python: Reformat with Black, except quotes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
5028c081cb
commit
11741543da
@@ -21,13 +21,17 @@ migration runs.
|
||||
logger = logging.getLogger('zulip.fix_unreads')
|
||||
logger.setLevel(logging.WARNING)
|
||||
|
||||
def build_topic_mute_checker(cursor: CursorObj, user_profile: UserProfile) -> Callable[[int, str], bool]:
|
||||
'''
|
||||
|
||||
def build_topic_mute_checker(
|
||||
cursor: CursorObj, user_profile: UserProfile
|
||||
) -> Callable[[int, str], bool]:
|
||||
"""
|
||||
This function is similar to the function of the same name
|
||||
in zerver/lib/topic_mutes.py, but it works without the ORM,
|
||||
so that we can use it in migrations.
|
||||
'''
|
||||
query = SQL('''
|
||||
"""
|
||||
query = SQL(
|
||||
'''
|
||||
SELECT
|
||||
recipient_id,
|
||||
topic_name
|
||||
@@ -35,26 +39,27 @@ def build_topic_mute_checker(cursor: CursorObj, user_profile: UserProfile) -> Ca
|
||||
zerver_mutedtopic
|
||||
WHERE
|
||||
user_profile_id = %s
|
||||
''')
|
||||
'''
|
||||
)
|
||||
cursor.execute(query, [user_profile.id])
|
||||
rows = cursor.fetchall()
|
||||
|
||||
tups = {
|
||||
(recipient_id, topic_name.lower())
|
||||
for (recipient_id, topic_name) in rows
|
||||
}
|
||||
tups = {(recipient_id, topic_name.lower()) for (recipient_id, topic_name) in rows}
|
||||
|
||||
def is_muted(recipient_id: int, topic: str) -> bool:
|
||||
return (recipient_id, topic.lower()) in tups
|
||||
|
||||
return is_muted
|
||||
|
||||
|
||||
def update_unread_flags(cursor: CursorObj, user_message_ids: List[int]) -> None:
|
||||
query = SQL('''
|
||||
query = SQL(
|
||||
'''
|
||||
UPDATE zerver_usermessage
|
||||
SET flags = flags | 1
|
||||
WHERE id IN %(user_message_ids)s
|
||||
''')
|
||||
'''
|
||||
)
|
||||
|
||||
cursor.execute(query, {"user_message_ids": tuple(user_message_ids)})
|
||||
|
||||
@@ -72,7 +77,8 @@ def fix_unsubscribed(cursor: CursorObj, user_profile: UserProfile) -> None:
|
||||
recipient_ids = []
|
||||
|
||||
def find_recipients() -> None:
|
||||
query = SQL('''
|
||||
query = SQL(
|
||||
'''
|
||||
SELECT
|
||||
zerver_subscription.recipient_id
|
||||
FROM
|
||||
@@ -85,7 +91,8 @@ def fix_unsubscribed(cursor: CursorObj, user_profile: UserProfile) -> None:
|
||||
zerver_recipient.type = 2 AND
|
||||
(NOT zerver_subscription.active)
|
||||
)
|
||||
''')
|
||||
'''
|
||||
)
|
||||
cursor.execute(query, {"user_profile_id": user_profile.id})
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
@@ -103,7 +110,8 @@ def fix_unsubscribed(cursor: CursorObj, user_profile: UserProfile) -> None:
|
||||
user_message_ids = []
|
||||
|
||||
def find() -> None:
|
||||
query = SQL('''
|
||||
query = SQL(
|
||||
'''
|
||||
SELECT
|
||||
zerver_usermessage.id
|
||||
FROM
|
||||
@@ -116,12 +124,16 @@ def fix_unsubscribed(cursor: CursorObj, user_profile: UserProfile) -> None:
|
||||
(zerver_usermessage.flags & 1) = 0 AND
|
||||
zerver_message.recipient_id in %(recipient_ids)s
|
||||
)
|
||||
''')
|
||||
'''
|
||||
)
|
||||
|
||||
cursor.execute(query, {
|
||||
"user_profile_id": user_profile.id,
|
||||
"recipient_ids": tuple(recipient_ids),
|
||||
})
|
||||
cursor.execute(
|
||||
query,
|
||||
{
|
||||
"user_profile_id": user_profile.id,
|
||||
"recipient_ids": tuple(recipient_ids),
|
||||
},
|
||||
)
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
user_message_ids.append(row[0])
|
||||
@@ -143,6 +155,7 @@ def fix_unsubscribed(cursor: CursorObj, user_profile: UserProfile) -> None:
|
||||
fix,
|
||||
)
|
||||
|
||||
|
||||
def fix(user_profile: UserProfile) -> None:
|
||||
logger.info('\n---\nFixing %s:', user_profile.id)
|
||||
with connection.cursor() as cursor:
|
||||
|
||||
Reference in New Issue
Block a user