本文整理汇总了Python中api_db_utils.APIDB.get_club_courses方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.get_club_courses方法的具体用法?Python APIDB.get_club_courses怎么用?Python APIDB.get_club_courses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_db_utils.APIDB
的用法示例。
在下文中一共展示了APIDB.get_club_courses方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trainee_club_details
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_courses [as 别名]
def trainee_club_details(req, uskey_club):
"""
``GET`` @ |ta| + ``/clubs/<uskey_club>``
Detail of a club
"""
club = req.model
j_club = club.to_dict()
j_club['member_count'] = APIDB.get_club_members(club, count_only=True)
j_club['courses'] = sanitize_list(APIDB.get_club_courses(club),
['id', 'name', 'start_date', 'end_date', 'course_type'])
j_club['owners'] = sanitize_list(APIDB.get_club_owners(club), ['name', 'picture'])
return sanitize_json(j_club, ['id', 'name', 'description', 'url', 'creation_date', 'is_open', 'owners',
'member_count', 'courses'])
示例2: coach_club_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_courses [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'])
示例3: coach_club_membership
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_courses [as 别名]
def coach_club_membership(req, uskey_membership):
"""
``GET`` @ |ca| + ``/memberships/<uskey_membership>``
Detail of a membership. |uroleOT|
"""
membership = req.model
member = membership.get_member
club = membership.get_club
ret = sanitize_json(membership.to_dict(), ['id', 'membership_type', 'status'])
ret['user'] = sanitize_json(member.to_dict(), ['id', 'nickname', 'avatar'])
# ret['course_count'] = APIDB.get_club_courses(club, count_only=True)
if membership.membership_type == "TRAINER":
courses = APIDB.get_club_courses_im_trainer_of(member, club)
else:
courses = APIDB.get_club_courses(club)
ret['subscriptions'] = sanitize_list(courses, ['id', 'name', 'description'])
return ret
示例4: trainee_club_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_courses [as 别名]
def trainee_club_list(req):
"""
``GET`` @ |ta| + ``/clubs``
List of the clubs
"""
# check if there's the filter
j_req = json_from_paginated_request(req, (('member', None),))
if hasattr(req, 'member'):
j_req['member'] = req.member
user_filter = j_req['member'] == 'true'
page = int(j_req['page'])
size = int(j_req['size'])
# if user and filter are true, then get from the clubs he's member of
if user_filter:
# get the user, just in case
user = GCAuth.get_user_or_none(req)
if user:
clubs, total = APIDB.get_user_member_of(user, paginated=True, page=page, size=size)
else:
raise AuthenticationError("member is set but user is missing")
else:
clubs, total = APIDB.get_clubs(paginated=True, page=page, size=size)
# render accordingly to the doc.
ret = {}
items = []
for club in clubs:
if not club.is_deleted:
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['owners'] = sanitize_list(APIDB.get_club_owners(club), ['name', 'picture'])
items.append(j_club)
ret['results'] = sanitize_list(items,
['id', 'name', 'description', 'url', 'creation_date', 'is_open', 'tags', 'owners',
'member_count', 'course_count'])
ret['total'] = total
return ret
示例5: coach_course_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_courses [as 别名]
def coach_course_list(req, uskey_club):
"""
``GET`` @ |ca| + ``/clubs/<uskey_club>/courses``
List of the courses of a club. |uroleOT|
"""
club = req.model
j_req = json_from_paginated_request(req, (('courseType', None), ('activeOnly', None),))
page = int(j_req['page'])
size = int(j_req['size'])
course_type = j_req['courseType']
active_only = j_req['activeOnly'] == "true"
courses, total = APIDB.get_club_courses(club, course_type=course_type, active_only=active_only,
paginated=True, page=page, size=size)
res_courses = []
for course in courses:
j_course = course.to_dict()
j_course["trainers"] = sanitize_list(APIDB.get_course_trainers(course), allowed=["id", "name", "picture"])
j_course["subscriber_count"] = APIDB.get_course_subscribers(course, count_only=True)
sessions_total = APIDB.get_course_sessions(course)
j_course['session_count'] = len(sessions_total)
sessions_finished = [session for session in sessions_total if session.status == "FINISHED"]
# logger.debug("%s %s %s", len(sessions_total), len(sessions_finished),long(sessions_finished)/long(sessions_total) * 100 )
if len(sessions_total) > 0:
j_course['completeness'] = long(len(sessions_finished)) / long(len(sessions_total)) * 100
else:
j_course['completeness'] = 0
allowed = ["id", "name", "description", "trainers", "subscriber_count", "session_count", "course_type",
"completeness", "profile", "max_level"]
if course.course_type == "SCHEDULED":
allowed += ["start_date", "end_date"]
elif course.course_type == "PROGRAM":
allowed += ["duration"]
res_course = sanitize_json(j_course, allowed=allowed)
res_courses.append(res_course)
ret = {}
ret['results'] = res_courses
ret['total'] = total
return ret
示例6: trainee_course_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_courses [as 别名]
def trainee_course_list(req, uskey_club):
"""
``GET`` @ |ta| + ``/clubs/<uskey_club>/courses``
List of the courses of a club
"""
club = req.model
j_req = json_from_paginated_request(req, (('course_type', None), 'activeOnly', ('subscribed', False)))
page = int(j_req['page'])
size = int(j_req['size'])
course_type = j_req['course_type']
active_only = j_req['activeOnly'] == "True"
subscribed = j_req['subscribed'] == "True"
if subscribed:
courses, total = APIDB.get_club_courses_im_subscribed_to(club, course_type=course_type, active_only=active_only,
paginated=True, page=page, size=size)
else:
courses, total = APIDB.get_club_courses(club, course_type=course_type, active_only=active_only,
paginated=True, page=page, size=size)
res_courses = []
for course in courses:
j_course = course.to_dict()
j_course["trainers"] = sanitize_list(APIDB.get_course_trainers(course), allowed=["id", "name", "picture"])
j_course["subscriber_count"] = APIDB.get_course_subscribers(course, count_only=True)
j_course["session_count"] = APIDB.get_course_sessions(course, count_only=True)
allowed = ["id", "name", "description", "trainers", "subscriber_count", "session_count", "course_type"]
if course.course_type == "SCHEDULED":
allowed += ["start_date", "end_date"]
elif course.course_type == "PROGRAM":
allowed += ["week_no", "day_no"]
res_course = sanitize_json(j_course, allowed=allowed)
res_courses.append(res_course)
ret = {}
ret['results'] = res_courses
ret['total'] = total
return ret
示例7: auth
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_courses [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'})
#.........这里部分代码省略.........