本文整理汇总了Python中api_db_utils.APIDB.get_session_im_trainer_of方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.get_session_im_trainer_of方法的具体用法?Python APIDB.get_session_im_trainer_of怎么用?Python APIDB.get_session_im_trainer_of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_db_utils.APIDB
的用法示例。
在下文中一共展示了APIDB.get_session_im_trainer_of方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coach_club_session_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_session_im_trainer_of [as 别名]
def coach_club_session_list(req, uskey_club):
"""
``GET`` @ |ca| + ``/clubs/<uskey_club>/sessions``
List of the sessions of a club. |uroleOT|
"""
club = req.model
j_req = json_from_paginated_request(req, (('status', None), ('notStatus', None), ('type', None),
('from', None),
('to', None)))
page = int(j_req['page'])
size = int(j_req['size'])
try:
date_from = datetime.datetime.fromtimestamp(long(j_req['from']) / 1000)
except Exception as e:
date_from = None
try:
date_to = datetime.datetime.fromtimestamp(long(j_req['to']) / 1000)
except Exception as e:
date_to = None
session_type = j_req['type']
role = APIDB.get_user_club_role(req.user, club)
logging.debug(j_req)
if role == "OWNER":
sessions, total = APIDB.get_club_sessions(club, date_from=date_from, date_to=date_to,
session_type=session_type, paginated=True,
not_status=j_req['notStatus'], page=page, size=size)
else:
sessions, total = APIDB.get_session_im_trainer_of(req.user, club, date_from=date_from, date_to=date_to,
session_type=session_type, paginated=True, page=page,
size=size)
res_list = []
for session in sessions:
res_obj = session.to_dict()
res_obj['status'] = session.status
res_obj['participation_count'] = APIDB.get_session_participations(session, count_only=True)
res_obj['course'] = sanitize_json(session.course.get(), allowed=['id', 'name'])
allowed = ['id', 'name', 'status', 'participation_count',
'session_type', 'course', 'created']
course_type = session.course.get().course_type
if course_type == "SCHEDULED":
allowed += ["start_date", "end_date"]
elif course_type == "PROGRAM":
allowed += ["week_no", "day_no"]
if session.session_type == "SINGLE":
allowed += ['url']
res_list.append(sanitize_json(res_obj, allowed=allowed))
return dict(total=total, results=res_list)