本文整理汇总了Python中models.comment.Comment.user方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.user方法的具体用法?Python Comment.user怎么用?Python Comment.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.comment.Comment
的用法示例。
在下文中一共展示了Comment.user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import user [as 别名]
def post(self, task_id):
# create new task (with parent)
task_key = ndb.Key(urlsafe=task_id)
# check if user is authed to reassign task
if not authed_for_task(task_key.get(), self.user_entity):
return self.abort(401)
# get user key
user_key = self.user_entity.key
# create new comment object
comment = Comment(parent=task_key)
# populate form with POST data
form = CommentForm(self.request.POST)
if form.validate():
# populate comment object with validated form data
form.populate_obj(comment)
# set reference properties on comment object
comment.task = task_key
comment.user = user_key
# store comment
comment.put()
# record history item
history_text = 'Comment added'
add_to_history(task_key.get(), self.user_entity, history_text)
# add a flash message to session
self.session.add_flash(history_text)
else:
# if form doesn't validate then add a flash message before redirecting
flash_msg = form.errors
self.session.add_flash(flash_msg)
# redirect to task view page
redirect_url = self.uri_for('task-view', task_id=task_key.urlsafe())
return self.redirect(redirect_url)