users.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:quizbot-2017 作者: pycontw 项目源码 文件源码
def generate_leaders(*, leader_factory=None):
    """Creates a generator for the leaderboard.

    Generates a 4-tuple containing the ranking, score, user object, and
    registration information of the leader. The result is a namedtuple.
    """
    if leader_factory is None:
        leader_factory = Leader
    cursor = db.get_cursor()
    cursor.execute("""
        SELECT "serial", "score"
        FROM "user"
        ORDER BY "score" DESC
    """)

    for ranking, (serial, score) in enumerate(cursor, 1):
        user = User(serial=serial)
        registration = registrations.get_registration(serial=serial)
        yield leader_factory(
            ranking=ranking, score=score,
            user=user, registration=registration,
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号