本文整理汇总了Python中blog.models.Comment.user方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.user方法的具体用法?Python Comment.user怎么用?Python Comment.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Comment
的用法示例。
在下文中一共展示了Comment.user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_article
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import user [as 别名]
def get_article(request,slug):
try:
article=Article.objects.get(slug=slug)
except ObjectDoesNotExist:
return HttpResponseRedirect('/')
try:
comments=Comment.objects.filter(article=article).order_by('-date','-id')
except ObjectDoesNotExist:
comments=None
if request.method == 'POST':
form = CommentForm(request.POST, **{'article':article,'ip':request.META['REMOTE_ADDR'],})
if form.is_valid():
comment=Comment()
comment.comment = form.cleaned_data['comment']
comment.article = article
if request.user.is_authenticated():
comment.user = request.user
comment.ip=request.META['REMOTE_ADDR']
comment.save()
return HttpResponseRedirect('/'+article.slug)
else:
form = CommentForm()
return render_to_response('blog/article.html', {
'form': form,
'article': article,
'comments':comments,
},context_instance=RequestContext(request))
示例2: post_detail
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import user [as 别名]
def post_detail(request, post_id):
context = RequestContext(request)
if request.method == 'GET':
try:
post = Post.objects.get(pk=post_id)
except Poll.DoesNotExist:
raise Http404
post_comment = Comment.objects.filter(post_id=post_id)
return render_to_response('blog/post_detail.html', { 'post': post, 'post_comment': post_comment, 'post_id': post_id}, context)
else:
try:
post = Post.objects.get(pk=post_id)
except Poll.DoesNotExist:
raise Http404
comment = Comment()
comment.content = request.POST['content']
comment.user = request.user
comment.post = post
comment.save()
return HttpResponseRedirect(reverse('post_detail', args=(post_id,)))
示例3: comment_create
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import user [as 别名]
def comment_create(request, post_slug):
try:
post = Post.objects.get(slug=post_slug)
except Post.DoesNotExist:
raise Http404()
if "content_raw" not in request.POST:
return redirect(
reverse("blog:post_detail", args=[post.category.name, post_slug]))
if not post.published and not request.user.is_superuser:
raise PermissionDenied()
comment = Comment()
if request.user.is_authenticated():
comment.user = request.user
else:
if ('user_name' not in request.POST or
'user_email' not in request.POST):
return redirect(
reverse(
"blog:post_detail", args=[post.category.name, post_slug]))
comment.user_name = request.POST['user_name']
comment.user_email = request.POST['user_email']
comment.content_raw = request.POST['content_raw']
comment.post = post
comment.save()
send_email_notification.delay(
title=u'Новый коментарии',
message=u'Новый коменатрии \n{0}\n{1}'.format(
reverse('blog:post_detail', args=[post.category.name, post_slug]),
datetime.datetime.now()))
return redirect(
reverse("blog:post_detail", args=[post.category.name, post_slug]))
示例4: addcomment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import user [as 别名]
def addcomment(request):
postid = request.GET.get('id')
id=request.POST['id']
username=request.POST['username']
email=request.POST['email']
content=request.POST['content']
psw=request.POST['psw']
t = loader.get_template("addcommentresult.html")
if (psw=="123456" and username!="" and email!="" and content!=""):
comment=Comment()
comment.user=username
comment.content=content
comment.email=email
post=Post.objects.get(id=postid)
comment.ofpost=post
comment.save()
post.comment_times+=1
post.save()
result="评论添加成功"
else:
result="评论添加不成功 请联系站长"
c = Context({"username":username,"result":result,"postid":postid,"id":id})
return HttpResponse(t.render(c))