本文整理汇总了Python中app.models.Comment.author方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.author方法的具体用法?Python Comment.author怎么用?Python Comment.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Comment
的用法示例。
在下文中一共展示了Comment.author方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import author [as 别名]
def post(self, blog_id=1, page=1):
data = request.json
blog = Blog.query.get(blog_id)
comment = Comment()
comment.detail = data['detail']
user_id = data['user_id']
user = User.query.get(user_id)
if user:
comment.author = user
else:
guest = User('guest','unused')
guest.id = 0
comment.author = guest
comment.article = blog
comment.createAt = datetime.now()
db.session.add(comment)
db.session.commit()
comments = Comment.query.filter_by(article=blog).paginate(page, PAGE_SIZE, False)
return comments
示例2: post
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import author [as 别名]
def post(self, slug):
context = self.get_context(slug)
form = context.get('form')
if form.validate():
comment = Comment()
form.populate_obj(comment)
comment.author = context.get('author')
post = context.get('post')
post.comments.append(comment)
post.save()
return redirect(url_for('posts.detail', slug=slug))
return render_template('posts/detail.html', **context)
示例3: staticUnity
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import author [as 别名]
def staticUnity(slug):
if request.method == 'POST':
unity = Unity.get_or_404(slug=slug)
form = CommentForm()
if not form.validate():
return render_template('unity/staticUnity.html',
pageTitle=unity.title,
unity=unity,
form=form)
else:
newComment = Comment(body=form.comment.data)
newComment.author = User.get(email=current_user.email)
unity.comments.append(newComment)
unity.save()
form.comment.data = None # resets field on refresh
flash('Comment Posted')
return render_template('unity/staticUnity.html',
pageTitle=unity.title,
unity=unity,
form=form)
elif request.method == 'GET':
try:
return render_template('unity/%s.html' % slug,
pageTitle=slug)
except TemplateNotFound:
unity = Unity.get_or_404(slug=slug)
currentUser = User.get(email=current_user.email)
if (unity.postType == 'draft' and
unity.author != currentUser and
currentUser.is_admin() is False):
flash('You must be draft author or admin to view.')
return redirect(url_for('.listUnity'))
else:
form = CommentForm()
return render_template('unity/staticUnity.html',
pageTitle=unity.title,
unity=unity,
form=form)