本文整理汇总了Python中models.Comment.post方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.post方法的具体用法?Python Comment.post怎么用?Python Comment.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.post方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: article
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post [as 别名]
def article(request, post_id, post_name):
post = Post.posts.get_visible_post(post_id)
if not post:
raise Http404
if request.method == "POST":
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
comment = Comment()
comment.author = comment_form.cleaned_data['author']
comment.post = post
comment.email = comment_form.cleaned_data['email']
comment.text = comment_form.cleaned_data['text']
comment.save()
return HttpResponseRedirect("/")
else:
# TODO SHOW ERRORS
pass
spotlighted = Project.objects.filter(related_posts=post)
comments = Comment.objects.filter(post=post)
related = TaggedItem.objects.get_related(post, Post)[:6]
comment_form = CommentForm()
return render_to_response('article.html',
{
"post": post,
"comments": comments,
"related": related,
"spotlighted": spotlighted,
"comment_form": comment_form
},
context_instance=RequestContext(request))
示例2: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post [as 别名]
def view_post(request, post_id):
post = Post.get_by_id(int(post_id))
if not post:
raise Http404
if not is_admin() and not post.is_published:
raise Http404
if request.method == "POST":
comment = Comment()
comment.content = request.POST["comment"]
comment.author = users.get_current_user()
comment.post = post
if request.POST["parent_comment"] != "":
parent_comment = Comment.get_by_id(int(request.POST["parent_comment"]))
comment.parent_comment = parent_comment
comment.put()
post.comment_count = post.comment_count + 1
post.put()
mail.send_mail(
sender="[email protected]",
to=post.author.email(),
subject=(u"牛逼 - 你的文章%s有了新评论" % post.title).encode("utf8"),
body=(
u"""%s在你的文章%s上留了评论:
%s
点击这个链接回复: http://www.niubi.de/post/%s/"""
% (comment.author.nickname(), post.title, comment.content, post.key().id())
).encode("utf8"),
)
comments = Comment.all().filter("post", post)
sent_users = []
for c in comments:
if not contains_user(sent_users, c.author):
mail.send_mail(
sender="[email protected]",
to=c.author.email(),
subject=(u"牛逼 - 你参与评论的文章%s有了新评论" % post.title).encode("utf8"),
body=(
u"""%s在文章%s上留了评论:
%s
点击这个链接回复: http://www.niubi.de/post/%s/"""
% (comment.author.nickname(), post.title, comment.content, post.key().id())
).encode("utf8"),
)
sent_users.append(c.author)
return HttpResponseRedirect("/post/%s" % post.key().id())
post.read_count = post.read_count + 1
post.put()
post.getComments()
return render_to_response(
"view_post.html",
{"post": post, "is_post_author": is_post_author(post_id)},
context_instance=RequestContext(request),
)
示例3: do_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post [as 别名]
def do_comment(request, post, attrs, all_comments=None):
# make sure the form came through correctly
if not ("name" in attrs and "text" in attrs and "email" in attrs and "lastname" in attrs):
return False
# 'lastname' is a honeypot field
if not attrs["lastname"] == "":
return False
# keyword parameter is for prefetching
if all_comments is None:
all_comments = list(post.comments.all())
else:
all_comments = all_comments[:] # copy so we don't mutate later
### create a new comment record
comment = Comment()
comment.post = post
comment.name = attrs["name"].strip()
if len(comment.name) == 0:
comment.name = "Anonymous"
comment.text = attrs["text"]
comment.email = attrs["email"]
### check for spam (requires a web request to Akismet)
is_spam = akismet_check(request, comment)
if is_spam:
return False # don't even save spam comments
comment.spam = False
### set the comment's parent if necessary
if "parent" in attrs and attrs["parent"] != "":
comment.parent_id = int(attrs["parent"])
if isLegitEmail(comment.email):
comment.subscribed = attrs.get("subscribed", False)
else:
comment.subscribed = False
# make sure comments under the same name have a consistent gravatar
comment.email = hashlib.sha1(comment.name.encode("utf-8")).hexdigest()
comment.save()
all_comments.append(comment)
### send out notification emails
emails = {}
for c in all_comments:
if c.subscribed and c.email != comment.email and isLegitEmail(c.email):
emails[c.email] = c.name
for name, email in settings.MANAGERS:
emails[email] = name
template = get_template("comment_email.html")
subject = "Someone replied to your comment"
for email, name in emails.iteritems():
text = template.render(Context({"comment": comment, "email": email, "name": name}))
msg = EmailMessage(subject, text, "[email protected]", [email])
msg.content_subtype = "html"
msg.send()
return True
示例4: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post [as 别名]
def post(self, slug):
context = self.get_context(slug)
form = context.get('form')
if form.validate():
comment = Comment()
form.populate_obj(comment)
post = context.get('post')
comment.post = post
comment.save()
return redirect(url_for('posts.detail', slug=slug))
return render_template('posts/detail.html', **context)
示例5: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post [as 别名]
def view_post(id):
form = request.forms
if form.update_comment :
post = Post.get(id=id)
comment = Comment()
comment.post = post # current post
comment.user = User.get(username=form.username)
comment.content = form.content
comment.pub_date = datetime.now()
comment.save()
redirect('/view/post/%d' %(id,))
else :
post = Post.get(id=id)
comments = Comment.filter(post__id = id)
return template('templates/post.html.tpl',post=post,comments=comments)
示例6: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post [as 别名]
def view_post(request, post_id):
post = Post.get_by_id(int(post_id))
if not post:
raise Http404
if not is_admin() and not post.is_published:
raise Http404
if request.method == 'POST':
comment = Comment()
comment.content = request.POST['comment']
comment.author = users.get_current_user()
comment.post = post
if request.POST['parent_comment'] != "":
parent_comment = Comment.get_by_id(int(request.POST['parent_comment']))
comment.parent_comment = parent_comment
comment.put()
post.comment_count = post.comment_count + 1
post.put()
mail.send_mail(sender="[email protected]",
to=post.author.email(),
subject=(u'牛逼 - 你的文章%s有了新评论'%post.title).encode('utf8'),
body=(u'''%s在你的文章%s上留了评论:
%s
点击这个链接回复: http://www.niubi.de/post/%s/''' %(comment.author.nickname(), post.title, comment.content, post.key().id())).encode('utf8')
)
comments = Comment.all().filter('post', post)
sent_users = []
for c in comments:
if not contains_user(sent_users, c.author):
mail.send_mail(sender="no-[email protected]",
to=c.author.email(),
subject=(u'牛逼 - 你参与评论的文章%s有了新评论'%post.title).encode('utf8'),
body=(u'''%s在文章%s上留了评论:
%s
点击这个链接回复: http://www.niubi.de/post/%s/''' %(comment.author.nickname(), post.title, comment.content, post.key().id())).encode('utf8')
)
sent_users.append(c.author)
return HttpResponseRedirect('/post/%s' % post.key().id())
post.read_count = post.read_count + 1
post.put()
post.getComments()
return render_to_response('view_post.html',
{'post':post,'is_post_author':is_post_author(post_id)}, context_instance=RequestContext(request))
示例7: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post [as 别名]
def post(request, id):
posts = Post.objects.all()
post = Post.objects.get(id=id)
comments = Comment.objects.filter(post = post, approved = True)
teve_comentario = False
if request.method == 'POST':
teve_comentario = True
comment = Comment()
comment.post = post
comment.name = request.POST['nome']
comment.email = request.POST['email']
comment.comment = request.POST['comentario']
comment.save()
return render(request, 'blog/post.html', locals())