当前位置: 首页>>代码示例>>Python>>正文


Python APIDB.get_club_all_members方法代码示例

本文整理汇总了Python中api_db_utils.APIDB.get_club_all_members方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.get_club_all_members方法的具体用法?Python APIDB.get_club_all_members怎么用?Python APIDB.get_club_all_members使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在api_db_utils.APIDB的用法示例。


在下文中一共展示了APIDB.get_club_all_members方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: trainee_club_members

# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_all_members [as 别名]
def trainee_club_members(req, uskey_club):
    """
    ``GET`` @ |ta| +  ``/clubs/<uskey_club>/members``

    List of the members of a club
    """
    club = req.model
    if uskey_club == "current":
        user = GCAuth.get_user(req)
        if APIDB.get_user_club_role(user, club) != "MEMBER":
            raise AuthenticationError("User is not subscribed to the course")
    j_req = json_from_paginated_request(req)
    page = int(j_req['page'])
    size = int(j_req['size'])
    role = req.get('role', None)
    status = req.get('status', "ACCEPTED")
    l_users = []
    if not role:
        members, total = APIDB.get_club_all_members(club, status=status, paginated=True, page=page, size=size,
                                                    merge="role")
    elif role == "MEMBER":
        members, total = APIDB.get_club_members(club, status=status, paginated=True, page=page, size=size)
    elif role == "TRAINER":
        members, total = APIDB.get_club_trainers(club, status=status, paginated=True, page=page, size=size)
    elif role == "OWNER":
        members, total = APIDB.get_club_owners(club, status=status, paginated=True, page=page, size=size)
    # if the query is paginated, and the previous call has already fetched enough people.
    else:
        raise BadParameters("Role does not exists %s" % role)

    for member in members:
        user_role = role
        if not user_role:
            # this is not very efficent.. but works
            user_role = member.role.membership_type
        if user_role == "MEMBER":
            res_user = sanitize_json(member, allowed=["nickname", "avatar", "id"])
        elif user_role == "TRAINER":
            res_user = sanitize_json(member, allowed=["name", "picture", "id"])
        elif user_role == "OWNER":
            res_user = sanitize_json(member, allowed=["name", "picture", "id"])
        res_user['type'] = user_role
        l_users.append(res_user)

    return dict(results=l_users, total=total)
开发者ID:gymcentral,项目名称:gymcentral,代码行数:47,代码来源:api_trainee.py


注:本文中的api_db_utils.APIDB.get_club_all_members方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。