本文整理汇总了Python中blog.models.Comment类的典型用法代码示例。如果您正苦于以下问题:Python Comment类的具体用法?Python Comment怎么用?Python Comment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Comment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_comment
def post_comment(request,blog_id):
blog=get_object_or_404(Blog,id=blog_id)
titl=request.POST['title']
content=request.POST['content']
c=Comment(title=titl,pub_date=timezone.now(),parent=blog,content=content,author=User.objects.get(id=1))
c.save()
return HttpResponse('Your comment has been posted!')
示例2: add_comment_to_post
def add_comment_to_post(id, subName, subComment):
blogPostObj = BlogPost.objects.get(pk=id)
addComment = Comment(name=subName, comment=subComment, blogPost=blogPostObj)
addComment.save()
return True
示例3: add_comment
def add_comment(request, slug):
"""Add a new comment."""
p = request.POST
post = Post.objects.get(slug=slug)
author_ip = get_ip(request)
if p.has_key("body") and p["body"]:
author = "Anonymous"
if p["author"]:
author = p["author"]
comment = Comment(post=post)
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
comment.author_ip = author_ip
comment.save()
messages.success(
request, "Thank you for submitting a comment. It will appear once reviewed by an administrator."
)
else:
messages.error(request, "Something went wrong. Please try again later.")
return HttpResponseRedirect(post.get_absolute_url())
示例4: comment
def comment(request):
fields = request.POST
parent_post = Entry.objects.get(pk=fields['entry-id'])
akismetData = {}
akismetData['user_ip'] = request.META['REMOTE_ADDR']
akismetData['user_agent'] = request.META['HTTP_USER_AGENT']
akismetData['referrer'] = request.META['HTTP_REFERER']
akismetData['comment_type'] = 'comment'
akismetData['comment_author'] = fields['who']
what = fields['what'].encode('ascii', 'ignore')
is_spam = ak.comment_check(what, akismetData)
new_comment = Comment(entry = parent_post,
who = fields['who'],
what = fields['what'],
is_spam = is_spam)
new_comment.save()
post_url = "%s#%s%d" % (parent_post.get_absolute_url(), Comment.COMMENT_ANCHOR, new_comment.id)
return HttpResponseRedirect( post_url )
示例5: add_comment
def add_comment(request, post_id):
#add new comment to our post
p = request.POST
if p.has_key("text") and p["text"]:
# if has no author then name him myself
author = "Nemo"
if p["comment_author"]:
author = p["comment_author"]
comment = Comment(post=Post.objects.get(pk=post_id))
# save comment form
cf = CommentForm(p, instance=comment)
cf.fields["comment_author"].required = False
comment = cf.save(commit=False)
# save comment instance
comment.comment_author = author
notify = True
comment.save()
return_path = redirect(request.META.get('HTTP_REFERER','/'))
return return_path
示例6: comment_entry_request
def comment_entry_request(request, post_id, user_id):
"""Triggered when a user inserts a comment in an specific entry"""
bp = Entry.objects.get(id=post_id)
# Form management
if request.method == 'POST': # If the form has been submitted...
form = SubmitCommentForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
comment = Comment(entry=bp,
author=User.objects.get(id=user_id),
text=request.POST['message'],
date=datetime.datetime.now(),
num=Comment.objects.filter(
entry=post_id).count() + 1,
quote=0)
comment.save()
return HttpResponseRedirect(reverse("singlepost", args=(post_id,)))
else:
form = SubmitCommentForm() # An unbound form
return HttpResponse(
_singleentry_template_gen(
request, 'blog/singlepost.html',
Entry.objects.get(id=post_id),
Comment.objects.filter(entry=post_id), form))
示例7: add_comment
def add_comment(request):
name = request.POST.get('name', '')
if not name.strip():
return HttpResponse('name error')
password = request.POST.get('password', '')
if not password.strip():
return HttpResponse('password error')
password = hashlib.md5(password.encode('utf-8')).hexdigest()
website = request.POST.get('website', '')
if not website.strip():
return HttpResponse('website error')
if website.find("http://") == -1 or website.find("https://") == -1:
website = "http://" + website
content = request.POST.get('content', '')
if not content.strip():
return HttpResponse('content error')
post_id = request.POST.get('post_id', '')
if not post_id.strip():
return HttpResponse('post_id error')
post = Post.objects.get(id=post_id)
print('blog.views.add_comment post_id{0}'.format(post_id), sys.stderr)
new_cmt = Comment(name=name, password=password, website=website, content=content, post=post)
new_cmt.save()
return redirect('blog.views.main', slug=post.slug)
示例8: show_blog
def show_blog(request, blog_id):
stats = mytools.get_stats(request)
try:
this_blog = Blog.objects.get(pk = blog_id)
except Blog.DoesNotExist:
raise Http404
if request.POST: #Save and refresh the comments.
response = HttpResponse()
response['Content-Type'] = 'text/plain'
user = request.POST.get('user')
email = request.POST.get('email')
this_content = request.POST.get('content')
ctime = datetime.now()
comment = Comment(user_name=user, email_addr=email, content=this_content, blog=this_blog, comment_time=ctime)
comment.save()
str_ctime = str(ctime).split('.')[0][:16]
response.write(str_ctime)
return response
this_blog.scan += 1
this_blog.save()
comments = Comment.objects.filter(blog__exact=this_blog)
tags = Tag.objects.all()
arch = mytools.get_arch()
return render_to_response('blog.html',
{'blog':this_blog, 'comments':comments, 'show_tags':tags, 'arch':arch, 'stats':stats}
)
示例9: reply_comment
def reply_comment(request):
data = request.POST.copy()
ctype = data.get("content_type")
object_pk = data.get("object_pk")
path=data.get('path')
user=request.user
try:
model = models.get_model(*ctype.split(".", 1))
target = model._default_manager.get(pk=object_pk)
except (TypeError,AttributeError,ObjectDoesNotExist):
logging.info('object not exits')
comment = Comment(content_type = ContentType.objects.get_for_model(target),
object_pk = force_unicode(target._get_pk_val()),
author=user.username,
email=user.email,
weburl=user.get_profile().website,
content=data.get('comment'),
date = datetime.now(),
mail_notify=True,
is_public = True,
parent_id = data.get('parent_id'),
)
comment.save()
signals.comment_was_submit.send(
sender = comment.__class__,
comment = comment
)
return HttpResponseRedirect(path)
示例10: comment
def comment(request):
if request.is_ajax():
form = CommentForm(request.POST)
if form.is_valid():
blog_id = request.GET.get('blog_id')
blog = get_object_or_404(Blog, pk=blog_id)
blog.comment_num += 1
blog.save()
# pre_comid = form.cleaned_data['pre_comid']
nickname = form.cleaned_data['anickname']
email = form.cleaned_data['bemail']
website = form.cleaned_data['cwebsite']
content = form.cleaned_data['dcontent']
photo = str(random.randint(0, 9)) + '.png'
u = User(name=nickname, email=email, website=website, photo=photo)
u.save()
c = Comment(user=u, blog=blog, content=content, comment_time=timezone.now())
c.save()
# sendCommentReply(email)
# SendEmail_Comment(nickname,None)
return ResponseMsg(True, u'谢谢你的评论')
else:
return ResponseMsg(False, form.errors.popitem()[1])
else:
raise Http404
示例11: post_comment
def post_comment(request, entry_id):
comment = Comment(entry_id = entry_id,
name = request.POST['name'],
comment = request.POST['comment'],
date = datetime.now())
comment.save();
return entry(request, entry_id)
示例12: get_post
def get_post(request, slug):
post = get_object_or_404(Post, slug=slug)
comments = Comment.objects.filter(post=post)
if request.method == "POST":
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
parent_id = request.POST.get('parent')
text = request.POST.get('text')
if parent_id:
parent = get_object_or_404(Comment, id=int(parent_id))
comment = Comment(post=post, text=text, author=request.user, parent=parent)
else:
comment = Comment(post=post, text=text, author=request.user,)
comment.save()
return http.HttpResponseRedirect(request.path)
else:
comment_form = CommentForm()
response = render(request, 'post.html', {
'post': post,
'comments': comments,
'comment_form': comment_form
})
cookie_name = 'viewed_%s' % post.id
if cookie_name not in request.COOKIES:
response.set_cookie(cookie_name, '1', 18000)
Post.objects.filter(slug=slug).update(views=F('views') + 1)
return response
示例13: save
def save(self, commit, Post_pk):
comment = Comment(message=self.cleaned_data['message'], author=self.cleaned_data['author'], image=self.cleaned_data['image'])
#이게 무슨 뜻인지?,
comment.post_id = Post_pk
if commit:
comment.save()
return comment
示例14: comment
def comment(request, post_id):
p = get_object_or_404(Post, pk=post_id)
if request.method == 'POST':
if request.user.is_authenticated():
form = AuthenticatedCommentForm(request.POST)
if form.is_valid():
cn = form.cleaned_data['name']
ce = form.cleaned_data['email']
ct = form.cleaned_data['comment']
c = Comment(post=p, name=cn, email=ce, text=ct)
c.save()
return HttpResponseRedirect(
reverse('blog.views.post', args=(p.id,)))
else:
pass
else:
if request.user.is_authenticated():
form = AuthenticatedCommentForm()
else:
form = AnonymousCommentForm()
cs = Comment.objects.filter(post=post_id).order_by('date')
return render_to_response('blog/post.html',
{'post': p, 'comments': cs, 'error_message': 'An error occurred.',
'form': form},
context_instance=RequestContext(request))
示例15: comment
def comment(request, post_id):
author = request.POST['author']
content = request.POST['comment']
post = get_object_or_404(Post, pk=post_id)
comment = Comment(author=author, comment=content, date=timezone.now(), post=post)
comment.save()
return HttpResponseRedirect(reverse('blog:detail', args=(post.id,)))