本文整理匯總了Python中server.models.User.get_last_thread方法的典型用法代碼示例。如果您正苦於以下問題:Python User.get_last_thread方法的具體用法?Python User.get_last_thread怎麽用?Python User.get_last_thread使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類server.models.User
的用法示例。
在下文中一共展示了User.get_last_thread方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: routine
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import get_last_thread [as 別名]
def routine(user: User, board: Board):
"""
Create new Thread linked to specified board, from POST JSON data.
:param user: Requesting User object
:param board: Board object
:return: New thread inside specified board
"""
try:
# Check thread JSON arguments
self.check_args()
self.validate_args()
# Process anon, image and construct new entity
anon = str_to_bool(self.args['anon'])
image = self.media_processing()
thread = Thread(anon, self.args['title'], self.args['text'], image, board.id, user.id)
# Add new Thread table to database
uchan.add_to_db(thread)
# Add new ThreadUser link
thread = user.get_last_thread()
uchan.add_to_db(ThreadUser(thread.id, user.id))
return responses.successful(201, JSONRepresentation.thread(thread, user))
except ValueError as msg:
return responses.client_error(400, '{}'.format(msg))
except KeyError as key:
return responses.client_error(400, 'Invalid parameter: {}'.format(key))