本文整理汇总了Python中api_db_utils.APIDB.get_club_trainers方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.get_club_trainers方法的具体用法?Python APIDB.get_club_trainers怎么用?Python APIDB.get_club_trainers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_db_utils.APIDB
的用法示例。
在下文中一共展示了APIDB.get_club_trainers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coach_club_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_trainers [as 别名]
def coach_club_list(req):
"""
``GET`` @ |ta| + ``/clubs``
List of the clubs
"""
# check if there's the filter
user = req.user
j_req = json_from_paginated_request(req, (('paginated', 'true'),))
page = int(j_req['page'])
size = int(j_req['size'])
paginated = j_req['paginated'] == 'true'
# if paginated then use the pagination..
if paginated:
clubs, total = APIDB.get_user_owner_or_trainer_of(user, paginated=True, page=page, size=size)
else:
clubs = APIDB.get_user_owner_or_trainer_of(user)
# render accordingly to the doc.
ret = {}
items = []
for club in clubs:
if not club.is_deleted:
j_club = club.to_dict()
j_club['role'] = club.membership.membership_type
j_club['member_count'] = APIDB.get_club_members(club, count_only=True)
j_club['course_count'] = APIDB.get_club_courses(club, count_only=True)
j_club['owner_count'] = APIDB.get_club_owners(club, count_only=True)
j_club['trainer_count'] = APIDB.get_club_trainers(club, count_only=True)
# j_club['owners'] = sanitize_list(APIDB.get_club_owners(club), ['id','name', 'picture'])
items.append(j_club)
j_club['trainers'] = sanitize_list(APIDB.get_club_trainers(club), ['id', 'name', 'picture'])
if paginated:
ret['results'] = sanitize_list(items,
['id', 'name', 'description', 'url', 'creation_date', 'is_open', 'tags',
'owner_count', 'trainer_count',
'member_count', 'course_count', 'trainers', 'role'])
ret['total'] = total
return ret
else:
return sanitize_list(items,
['id', 'name', 'description', 'url', 'creation_date', 'is_open', 'tags', 'owner_count',
'trainer_count',
'member_count', 'course_count', 'trainers', 'role'])
示例2: coach_club_details
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_trainers [as 别名]
def coach_club_details(req, uskey_club):
"""
``GET`` @ |ca| + ``/clubs/<uskey_club>``
Detail of a club. |uroleOT|
"""
club = req.model
j_club = club.to_dict()
j_club['member_count'] = APIDB.get_club_members(club, count_only=True)
j_club['course_count'] = APIDB.get_club_courses(club, count_only=True)
# j_club['courses'] = sanitize_list(APIDB.get_club_courses(club),
# ['name', 'start_date', 'end_date', 'course_type'])
j_club['owners'] = sanitize_list(APIDB.get_club_owners(club), ['id', 'name', 'picture'])
j_club['trainers'] = sanitize_list(APIDB.get_club_trainers(club), ['id', 'name', 'picture'])
return sanitize_json(j_club, ['id', 'name', 'description', 'url', 'creation_date', 'is_open', 'owners', 'trainers',
'member_count', 'course_count', 'tags'])
示例3: trainee_club_members
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_trainers [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)