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


Python User.get_by_id方法代码示例

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


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

示例1: removeUserFromProject

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_id [as 别名]
def removeUserFromProject(token, userId, projectId):
    """
    <span class="card-title">>This Call will remove a user from a project</span>
    <br>
    <b>Route Parameters</b><br>
        - seToken: 'seToken'<br>
        - userId: 0987654321,<br>
        - 'projectId': 1234567890<br>
    <br>
    <br>
    <b>Payload</b><br>
     - NONE
     {<br>
    }<br>
    <br>
    <b>Response</b>
    <br>
    200 - User updated
    <br>
    400 - Bad Request
    """

    requestingUser = get_user_by_token(token)
    if requestingUser is None:
        return bad_request("Bad User Token")

    try:
        userToRemove = User.get_by_id(int(userId))
    except Exception as e:
        return bad_request("Bad id format")


    if userToRemove is None:
        return bad_request("No such user to remove")

    #check project Exists
    project = Project.get_by_id(int(projectId))
    if project is None:
        return bad_request("No such Project!")

    #check if user is owner of project
    if requestingUser.key().id() != project.master_id:
        # check if user want to delete itself
        if requestingUser.key().id() != userToRemove.key().id():
            return forbidden("No permission to delete user")

    try:
        userToRemove.projects_id_list.remove(projectId)
        project.membersId.remove(userToRemove.key().id())
    except Exception as e:
        return bad_request("user is not listed to this project")



    db.put(userToRemove)
    db.put(project)
    db.save
    return Response(response=userToRemove.to_JSON(),
                            status=200,
                            mimetype="application/json")  # Real response!
开发者ID:jce-il,项目名称:SE-Hub,代码行数:62,代码来源:UserRoutes.py

示例2: update_user_session

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_id [as 别名]
def update_user_session(new_user=None):
    if new_user is None:
        old_user = get_current_user()
        if not old_user:
            return None
        new_user = User.get_by_id(old_user.key().id())
    get_current_session()['user'] = new_user
开发者ID:bahar,项目名称:movie-collection,代码行数:9,代码来源:__init__.py

示例3: removeUserFromCampus

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_id [as 别名]
def removeUserFromCampus(token, userId, campusId):
    """
    <span class="card-title">>This Call will remove a user from a campus</span>
    <br>
    <b>Route Parameters</b><br>
        - seToken: 'seToken'<br>
        - userId: 0987654321,<br>
        - 'campusId': 1234567890<br>
    <br>
    <br>
    <b>Payload</b><br>
     - NONE
     {<br>
    }<br>
    <br>
    <b>Response</b>
    <br>
    200 - User updated
    <br>
    400 - Bad Request
    """

    requestingUser = get_user_by_token(token)
    if requestingUser is None:
        return bad_request("Bad User Token")

    try:
        userToRemove = User.get_by_id(int(userId))
    except Exception as e:
        return bad_request("Bad id format")

    if userToRemove is None:
        return bad_request("No such user to remove")

    #check Campus Exists
    campus = Campus.get_by_id(int(campusId))
    if campus is None:
        return bad_request("No such Campus!")

    #check if user is owner of Campus
    if requestingUser.key().id() != campus.master_user_id:
        # check if user want to delete itself
        if requestingUser.key().id() != userToRemove.key().id():
            return forbidden("No permission to delete user")

    #remove campus from user campus list
    try:
        userToRemove.campuses_id_list.remove(campusId)
    except Exception as e:
        return bad_request("user is not listed to this campus")


    db.put(userToRemove)
    db.save
    return Response(response=userToRemove.to_JSON(),
                            status=200,
                            mimetype="application/json")  # Real response!
开发者ID:jce-il,项目名称:SE-Hub,代码行数:59,代码来源:UserRoutes.py

示例4: to_JSON

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_id [as 别名]
 def to_JSON(self):
     members = []
     for id in self.membersId:
         members.append(dict(json.loads(User.get_by_id(int(id)).to_JSON())))
     data = {
         "projectName": self.projectName,
         "courseId": self.courseId,
         "master_id": self.master_id,
         "grade": self.grade,
         "logo_url": self.logo_url,
         "gitRepository": self.gitRepository,
         "members": members,
         "info": json.loads(self.info),
         "id": self.key().id(),
     }
     return json.dumps(data)
开发者ID:jce-il,项目名称:SE-Hub,代码行数:18,代码来源:Project.py

示例5: to_JSON

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_id [as 别名]
 def to_JSON(self):
     user = User.get_by_id(self.master_id)
     if self.isProject:
         group = Project.get_by_id(self.groupId)
     else:
         group = Course.get_by_id(self.groupId)
     data = {
             'groupId' : self.groupId,
             'message' : self.message,
             'date' : {
                 'year': self.msgDate.year,
                 'month': self.msgDate.month,
                 'day': self.msgDate.day,
                 'hour': self.msgDate.hour,
                 'minute': self.msgDate.minute
             },
             'id' : self.key().id(),
             'master_id' : self.master_id,
             'isProject' : self.isProject,
             'user': json.loads(user.to_JSON()),
             'group': json.loads(group.to_JSON())
     }
     return json.dumps(data)
开发者ID:jce-il,项目名称:SE-Hub,代码行数:25,代码来源:Message.py

示例6: get_user_by_id

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_id [as 别名]
def get_user_by_id(id):
    u = User.get_by_id(id)
    return u
开发者ID:jce-il,项目名称:SE-Hub,代码行数:5,代码来源:Validation_Utils.py

示例7: removeUserFromCourse

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_id [as 别名]
def removeUserFromCourse(token, userId, courseId):
    """
    <span class="card-title">>This Call will remove a user from a course</span>
    <br>
    <b>Route Parameters</b><br>
        - seToken: 'seToken'<br>
        - userId: 0987654321,<br>
        - 'courseId': 1234567890<br>
    <br>
    <br>
    <b>Payload</b><br>
     - NONE
     {<br>
    }<br>
    <br>
    <b>Response</b>
    <br>
    200 - User updated
    <br>
    400 - Bad Request
    """

    requestingUser = get_user_by_token(token)
    if requestingUser is None:
        return bad_request("Bad User Token")

    try:
        userToRemove = User.get_by_id(int(userId))
    except Exception as e:
        return bad_request("Bad id format")

    if userToRemove is None:
        return bad_request("No such user to remove")

    #check Course Exists
    course = Course.get_by_id(int(courseId))
    if course is None:
        return bad_request("No such Course!")

    #check if user is owner of Course
    if requestingUser.key().id() != course.master_id:
        # check if user want to delete itself
        if requestingUser.key().id() != userToRemove.key().id():
            return forbidden("No permission to delete user")

    try:
        userToRemove.courses_id_list.remove(courseId)
        course.membersId.remove(userToRemove.key().id())
    except Exception as e:
        return bad_request("user is not listed to this course")

    #remove user from all projects in course
    projects = Project.all().filter("courseId =", course.key().id())
    for p in projects:
        if p.key().id() in userToRemove.projects_id_list:
            userToRemove.projects_id_list.remove(p.key().id())
            p.membersId.remove(userToRemove.key().id())
            db.put(p)


    db.put(userToRemove)
    db.put(course)
    db.save
    return Response(response=userToRemove.to_JSON(),
                            status=200,
                            mimetype="application/json")  # Real response!
开发者ID:jce-il,项目名称:SE-Hub,代码行数:68,代码来源:UserRoutes.py

示例8: getUsersByProject

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_id [as 别名]
def getUsersByProject(token, projectId):
    """
    <span class="card-title">>This Call will return all users in Project</span>
    <br>
    <b>Route Parameters</b><br>
        - seToken: 'seToken'<br>
        - projectId: 123456789
    <br>
    <br>
    <b>Payload</b><br>
     - NONE
    <br>
    <br>
    <b>Response</b>
    <br>
    200 - JSON Example:<br>
    <code>
        {<br>
        'username': 'DarkLord',<br>
        'name': 'Darth Vader',<br>
        'email': '[email protected],<br>
        'isLecturer': 'True',<br>
        'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',<br>
        'avatar_url': 'http://location.git.com/somthing'<br>
        'isFirstLogin': False,<br>
        'campuses_id_list': [43243532532,5325325325,532532342],<br>
        'courses_id_list': [53523,43432423,432432432432]<br>
        }
    </code>
    <br>
    403 - No User Found
    """
    if token is None:
        return no_content("Token Is Empty, No User Found")

    user = get_user_by_token(token)
    if user is None:
        return bad_request("Bad User Token")

    try:
        project = Project.get_by_id(int(projectId))
    except Exception as e:
        return bad_request("Bad id format")

    if project is None:
        return bad_request("No such Project")

    arr = []

    for u in enumerate(project.membersId):
        u = json.loads(User.get_by_id(int(u)).to_JSON())
        arr.append(dict(u))

    if len(arr) != 0:
            return Response(response=json.dumps(arr),
                            status=200,
                            mimetype="application/json")
    else:
        return Response(response=[],
                        status=200,
                        mimetype="application/json")
开发者ID:jce-il,项目名称:SE-Hub,代码行数:63,代码来源:UserRoutes.py


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