当前位置: 首页>>代码示例>>Python>>正文


Python APIDB.update_user方法代码示例

本文整理汇总了Python中api_db_utils.APIDB.update_user方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.update_user方法的具体用法?Python APIDB.update_user怎么用?Python APIDB.update_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在api_db_utils.APIDB的用法示例。


在下文中一共展示了APIDB.update_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: trainee_profile

# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import update_user [as 别名]
def trainee_profile(req):
    """
    ``GET`` @ |ta| + ``/user/current``

    ``PUT`` @ |ta| +  ``/user/current``

    - Profile of the current user.
    - Updates the profile of the user.
    - |ul|
    """
    out = ['id', 'name', 'nickname', 'gender', 'picture', 'avatar', 'birthday', 'country', 'city', 'language',
           'email', 'phone', 'active_club', 'sensors']
    if req.method == "GET":
        return sanitize_json(req.user, out, except_on_missing=False)
    elif req.method == "PUT":
        j_req = json_from_request(req,
                                  optional_props=['name', 'nickname', 'gender', 'picture', 'avatar', 'birthday',
                                                  'country', 'city', 'language',
                                                  'email', 'phone', 'activeClub', 'sensors'])
        if 'active_club' in j_req:
            membership = APIDB.get_user_club_role(req.user, Key(urlsafe=j_req['active_club']))
            if membership != "MEMBER":
                raise BadRequest("It seems that you want to activate a club that you are not member of")
        update, user = APIDB.update_user(req.user, **j_req)
        s_token = GCAuth.auth_user_token(user)
        deferred.defer(sync_user, user, s_token)
        return sanitize_json(user, out, except_on_missing=False)
开发者ID:gymcentral,项目名称:gymcentral,代码行数:29,代码来源:api_trainee.py

示例2: coach_profile

# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import update_user [as 别名]
def coach_profile(req):
    """
    ``GET`` @ |ca| +  ``/users/current``

    Profile of the current user |ul|
    """
    # list of parameters for the output
    out = ['id', 'name', 'nickname', 'gender', 'picture', 'avatar', 'birthday', 'country', 'city', 'language',
           'email', 'phone',
           # 'memberships',
           'owner_club']
    # if it's a detail
    if req.method == "GET":
        # req.user is always mapped to the user that makes the request.
        j_user = req.user.to_dict()
        # to add the memebrship
        # j_user['memberships'] = sanitize_list(APIDB.get_user_member_of_type(req.user, ['OWNER', 'TRAINER']),
        # ['id', 'name', 'description'])

        # this set the owner_club field if the user is not owner of any club. Other
        if 'owner_club' not in j_user:
            j_user['owner_club'] = None
        #  sanitize the result
        return sanitize_json(j_user, out, except_on_missing=False)
    # if it's an update, probably better to split in two calls..
    elif req.method == "PUT":
        j_req = json_from_request(req, optional_props=['name', 'nickname', 'gender', 'picture', 'avatar', 'birthday',
                                                       'country', 'city', 'language',
                                                       'email', 'phone', 'ownerClub'])
        if 'owner_club' in j_req:
            try:
                club = Key(urlsafe=j_req['owner_club']).get()
            except Exception as ex:
                raise BadParameters("It seems that the club does not exists")
            membership = APIDB.get_user_club_role(req.user, club)
            if membership != "OWNER" and membership != "TRAINER":
                raise BadRequest("It seems that you want to activate a club that you are not owner or trainer of")

        update, user = APIDB.update_user(req.user, **j_req)
        j_user = user.to_dict()
        j_user['memberships'] = sanitize_list(APIDB.get_user_member_of_type(req.user, ['OWNER', 'TRAINER']),
                                              ['id', 'name', 'description'])
        s_token = GCAuth.auth_user_token(user)
        deferred.defer(sync_user, user, s_token)
        return sanitize_json(j_user, out)
开发者ID:gymcentral,项目名称:gymcentral,代码行数:47,代码来源:api_coach.py


注:本文中的api_db_utils.APIDB.update_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。