예제 #1
0
def build_topic_mute_checker(
    cursor: CursorWrapper, 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(
        """
        SELECT
            recipient_id,
            topic_name
        FROM
            zerver_usertopic
        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}

    def is_muted(recipient_id: int, topic: str) -> bool:
        return (recipient_id, topic.lower()) in tups

    return is_muted
예제 #2
0
def dictfetchall(cursor: CursorWrapper) -> List[Dict[str, Any]]:
    "Returns all rows from a cursor as a dict"
    desc = cursor.description
    return [
        dict(zip((col[0] for col in desc), row)) for row in cursor.fetchall()
    ]