本文整理汇总了Python中api_db_utils.APIDB.get_club_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.get_club_by_id方法的具体用法?Python APIDB.get_club_by_id怎么用?Python APIDB.get_club_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_db_utils.APIDB
的用法示例。
在下文中一共展示了APIDB.get_club_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_request
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_by_id [as 别名]
def edit_request(router, request, response): # pragma: no cover
"""
Automatically loads into the ``request.model`` (where the value of ``.model`` is set in ``cfg.MODEL_NAME``, in this deployent has the value `model`) the object retrieved from
the parameter passed if these two requirements are satisfied:.
- The parameter **must** be a ``Key`` encoded as ``urlsafe``.
- The name of the parameter encoded into the url **must** start with ``uskey`` (which stands for UrlSafeKEY)
If the ``key`` does not exists it raises and exception.
example::
@app.route("/%s/hw/<uskey_obj>" % APP_ADMIN, methods=('GET', )) #method annotation, note the `uskey` param
def hw_par(req, uskey_obj): #method def, `uskey` param
model = req.model #automatically mapped..
.. note::
similarly, `req.user` is set by the decorator `user_required` in the `auth.py` of the `gaebasepy` submodule
:param router: the router
:param request: the request
:param response: the response
:return: the request edited
"""
# check that there's a valid app code
# depending on the url...
app_id = request.headers.get("X-App-Id")
if "trainee" in request.url:
# NOTE: change the config with the value if you want to change them
if not app_id in cfg.APPIDS_TRAINEE:
raise AuthenticationError("Your key %s is not valid" % app_id)
elif "coach" in request.url:
if not app_id in cfg.APPIDS_COACH:
raise AuthenticationError("Your key %s is not valid" % app_id)
kwargs = router.match(request)[2]
if kwargs:
if len(kwargs) >= 1:
key, value = kwargs.popitem()
# i suppose that 'uskey' for the name is used when it's a UrlSafeKEY.
# this kind of key can be loaded here
if key.startswith("uskey"):
if hasattr(request, 'model'):
return request
if value != "current":
try:
model = Key(urlsafe=value).get()
if not model.active:
raise NotFoundException()
setattr(request, cfg.MODEL_NAME, model)
except:
raise NotFoundException()
else:
# NOTE: api works also with the word `curren` as uskey parameter, in that case we do this trick to load the correct model.
# crurent works only for club..
if key.endswith("club"):
user = GCAuth.get_user(request)
if not user.active_club:
raise AuthenticationError("user has not active club")
club = APIDB.get_club_by_id(user.active_club)
if not club:
raise AuthenticationError("user has not active club")
setattr(request, cfg.MODEL_NAME, club)
return request
return request
示例2: __get_current_club
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_club_by_id [as 别名]
def __get_current_club(user):
if not user.active_club:
raise AuthenticationError("user has not active club")
return APIDB.get_club_by_id(user.active_club)