本文整理汇总了Python中api_db_utils.APIDB.get_user_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.get_user_by_id方法的具体用法?Python APIDB.get_user_by_id怎么用?Python APIDB.get_user_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_db_utils.APIDB
的用法示例。
在下文中一共展示了APIDB.get_user_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coach_course_subscription_create
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_user_by_id [as 别名]
def coach_course_subscription_create(req, uskey_course):
"""
``POST`` @ |ca| + ``/courses/<uskey_course>/subscriptions``
Creates a subscription for the coruse. |uroleOT|
"""
course = req.model
j_req = json_from_request(req, mandatory_props=['userId', 'role'],
optional_props=['profileLevel'])
user = APIDB.get_user_by_id(j_req['user_id'])
if j_req['role'] == "MEMBER":
if 'profile_level' not in j_req:
raise BadParameters("profileLevel is missing")
APIDB.add_member_to_course(user, course, status="ACCEPTED", profile_level=j_req['profile_level'])
elif j_req['role'] == "TRAINER": # only owners can add coaches
# if not APIDB.get_user_club_role(req.user, course.club) == "OWNER":
# raise AuthenticationError("User is not a OWNER")
APIDB.add_trainer_to_course(user, course)
return HttpEmpty()
示例2: coach_club_membership_create
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_user_by_id [as 别名]
def coach_club_membership_create(req, uskey_club):
"""
``POST`` @ |ca| + ``/clubs/<uskey_club>/memberships``
Add a membership for the user specified in the body ``userId``. |uroleOT|
"""
# FIXME: how delete works?
j_req = json_from_request(req, ["userId", "membershipType"], [("endDate", None)])
user = APIDB.get_user_by_id(j_req['user_id'])
membership_type = j_req.pop('membership_type')
if membership_type == "MEMBER":
APIDB.add_member_to_club(user, req.model, status="ACCEPTED", end_date=j_req['end_date'])
elif membership_type == "TRAINER":
APIDB.add_trainer_to_club(user, req.model, status="ACCEPTED", end_date=j_req['end_date'])
elif membership_type == "OWNER":
APIDB.add_owner_to_club(user, req.model, end_date=j_req['end_date'])
else:
raise BadParameters("Value %s is not valid for field 'type'" % j_req['type'])
req.model = APIDB.get_membership(user, req.model)
return HttpCreated(coach_club_membership(req, None))