本文整理汇总了Python中api_db_utils.APIDB.add_member_to_course方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.add_member_to_course方法的具体用法?Python APIDB.add_member_to_course怎么用?Python APIDB.add_member_to_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_db_utils.APIDB
的用法示例。
在下文中一共展示了APIDB.add_member_to_course方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coach_course_subscription_create
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import add_member_to_course [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: auth
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import add_member_to_course [as 别名]
def auth(req, provider, token): # pragma: no cover
"""
``GET`` @ |ta| ``/auth/<provider>/<token>``
This function handles the authentication via social networks
.. note::
supports:
- facebook
- google
:param req: the request
:param provider: the provider, e.g., ``facebook``
:param token: the token
:return: a webApp2 Response object
"""
# the pragma no cover is to skip the testing on this method, which can't be tested
# get user infos
d_user, token, error = GCAuth.handle_oauth_callback(token, provider)
if error:
raise AuthenticationError(error)
# check if user exists..
# logging.debug("%s %s %s" % (d_user, token, error))
auth_id = str(provider) + ":" + d_user['id']
user = User.get_by_auth_id(auth_id)
email = d_user['email']
# we check if users access with another social network
user_via_mail = User.query(ndb.GenericProperty('email') == email).get()
if user_via_mail:
user_via_mail.add_auth_id(auth_id)
user = user_via_mail
# create the user..
created = False
if not user:
if provider == 'google':
created, user = User.create_user(auth_id,
# unique_properties=['email'],
name=d_user.get('name', 'unknown'),
nickname="",
gender=d_user.get('gender', 'unknown')[0],
picture=d_user.get('picture', None),
avatar="",
birthday=datetime.datetime.now(),
country="",
city="",
language=d_user.get('locale', 'en'),
email=d_user.get('email', '[email protected]'),
phone="",
active_club=None,
owner_club=None,
sensors=[])
elif provider == 'facebook':
created, user = User.create_user(auth_id,
# unique_properties=['email'],
name=d_user.get('name', 'unknown'),
nickname="",
gender=d_user.get('gender', 'unknown')[0],
picture="http://graph.facebook.com/%s/picture?type=large" % d_user.get(
'id', None),
avatar="",
birthday=datetime.datetime.now(),
country="",
city="",
language=d_user.get('locale', 'en'),
email=d_user.get('email', '[email protected]'),
phone="",
active_club=None,
owner_club=None,
sensors=[])
else:
raise AuthenticationError("provider not allowed")
if not created:
logging.error(
"something is wrong with user %s with this token %s and this provider %s - unique %s" % (
d_user, token, provider, user))
raise AuthenticationError(
"Something is wrong with your account, these properties must be unique %s." % user)
else:
free_club = Club.query(Club.name == cfg.DEMO_CLUB).get()
if free_club:
courses = APIDB.get_club_courses(free_club)
for course in courses:
APIDB.add_member_to_course(user, course, status="ACCEPTED")
s_token = GCAuth.auth_user_token(user)
# if we crate the response, then we need the cors stuff.
# response = webapp2.Response(content_type='application/json', charset='UTF-8')
# if created:
# response.status = 201
# cookie = GCAuth.get_secure_cookie(token)
# response.set_cookie('gc_token', cookie, secure=False,
# max_age=int(cfg.AUTH_TOKEN_MAX_AGE), domain="/")
token = GCAuth.get_token(s_token)
# resp.headers.update({
# 'Access-Control-Allow-Origin': origin,
# 'Access-Control-Allow-Credentials': 'true'})
#.........这里部分代码省略.........