本文整理汇总了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!
示例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
示例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!
示例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)
示例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)
示例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
示例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!
示例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")