本文整理汇总了Python中models.Comment.add_comment方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.add_comment方法的具体用法?Python Comment.add_comment怎么用?Python Comment.add_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.add_comment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_view
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import add_comment [as 别名]
def post_view(request, post_pk):
if 'tree' in request.GET:
is_tree = bool(request.GET.get('tree'))
res = redirect('post_view', post_pk=post_pk)
if is_tree:
res.set_cookie('comments_tree', is_tree)
else:
res.delete_cookie('comments_tree')
return res
is_tree = request.COOKIES.get('comments_tree')
page = request.GET.get('page', 1)
post = BlogInterface(request.user).get_post_with_comments(post_pk,
as_tree=is_tree, get_recommends=True)
comments = post.comments_post
try:
page = int(page)
except ValueError:
return redirect('post_view', post_pk)
paginate = Paginator(comments, COMMENTS_PER_PAGE)
try:
page = paginate.page(page)
except (EmptyPage, InvalidPage):
page = paginate.page(paginate.num_pages)
comments = page.object_list
reply_to = request.GET.get('reply_to')
if reply_to:
reply_to = get_object_or_404(Comment, post=post_pk, number=reply_to)
form_p = FormProcessor(PostForm, request)
form_p.process()
if form_p.is_valid():
message = form_p.data['body']
Comment.add_comment(post, request.user, message, reply_to)
return redirect('post_view', post_pk=post.pk)
context = {}
context['post'] = post
context['user_blog'] = post.user
context['page'] = page
context['comments'] = comments
context['is_tree'] = is_tree
context['recommends'] = post.recommend_users
context['reply_form'] = form_p.form
context['reply_to'] = reply_to
return render_template(request, 'blog/post_view.html', context)
示例2: reply_add
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import add_comment [as 别名]
def reply_add(request, post_pk, reply_to=None):
post = get_object_or_404(Post, pk=post_pk)
if reply_to:
reply_to = get_object_or_404(Comment, post=post_pk, number=reply_to)
form_p = FormProcessor(PostForm, request)
form_p.process()
if form_p.is_valid():
user = request.user
data = form_p.data
message = data['body']
Comment.add_comment(post, user, message, reply_to)
return redirect('post_view', post_pk=post.pk)
context = {}
context['form'] = form_p.form
return render_template(request, 'blog/post_add.html', context)
示例3: add_reply
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import add_comment [as 别名]
def add_reply(self, text, post_id, reply_number=None, from_client='web'):
from models import BlackList, Comment
user = self.user
post = self.get_post(post_id)
if user.pk != post.user_id and post.tags.filter(name='readonly'):
raise PostInterfaceError(
"Sorry, you can't reply to this post, it is *readonly.")
if BlackList.objects.filter(user=post.user_id,
blacklisted_user=user).exists():
raise PostInterfaceError(
"Sorry, you can't reply to this user posts.")
reply_to = None
if reply_number:
reply_to = self.get_comment(post_id, reply_number)
reply = Comment.add_comment(post, user, text, reply_to,
from_client=from_client)
return reply