本文整理汇总了Python中models.Comment.thread_id方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.thread_id方法的具体用法?Python Comment.thread_id怎么用?Python Comment.thread_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.thread_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import thread_id [as 别名]
def edit_comment(request, thread_id, comment_id=None):
if comment_id:
comment = get_object_or_404(Comment, pk=comment_id)
else:
comment = Comment()
comment.thread_id = thread_id
if request.method == 'POST':
# comment_form = CommentForm(request.POST, instance=comment)
# v = comment_form.is_valid()
# if v:
# # スパム襲来のため投稿編集を禁止
# # comment_form.save()
# pass
#
# # validationがtrueならjsonで結果を返す
# ajax = request.GET.get('use-ajax', None)
# if ajax != 'true':
# # ajaxでない
# if v:
# # validならリダイレクト
# return http.HttpResponseRedirect('/bbs/%s' % comment.thread_id)
# else:
# # invalidなら下で処理
# context = request.POST
# else:
# # ajaxなときvalid,invalid問わず
# content = dict(result=v, errors=comment_form.errors, redirect_to=reverse(
# 'bbs.thread.show', args=(comment.thread.id, )))
# return http.HttpResponse(json.dumps(content), mimetype='text/plain')
return http.HttpResponse(content='', content_type='text/plain', status=400)
else:
# postでないajaxでない(普通のアクセス)
context = {}
comment_form = CommentForm(instance=comment, initial=dict(edit_key=''))
return render_to_response('bbs/edit_comment.html',
dict(
comment=comment,
comment_form=comment_form,
),
context_instance=RequestContext(request, context))
示例2: show_thread
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import thread_id [as 别名]
def show_thread(request, thread_id):
thread = get_object_or_404(Thread, pk=thread_id)
if thread.locked:
if not request.user.is_active:
return http.HttpResponseRedirect('/auth/login?next=%s' % request.path)
if request.method == 'POST':
comment = Comment()
comment.thread_id = thread_id
comment_form = CommentForm(request.POST, instance=comment)
v = comment_form.is_valid()
if v:
thread = comment_form.save()
ajax = request.GET.get('use-ajax', None)
if ajax != 'true':
if v:
return http.HttpResponseRedirect(reverse('bbs.thread.show', args=(thread_id,)))
else:
context = request.POST
else:
content = dict(result=v, errors=comment_form.errors, redirect_to=reverse(
'bbs.thread.show', args=(thread_id,)))
return http.HttpResponse(json.dumps(content), mimetype='text/plain')
else:
context = {}
comment_form = CommentForm()
return render(
request,
'bbs/show_thread.html',
dict(
thread=thread,
comments=thread.comment_set.all(),
comment_form=comment_form,
delete_form=DeleteForm()
),
context_instance=RequestContext(request, context)
)