本文整理汇总了Python中models.Comment.email方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.email方法的具体用法?Python Comment.email怎么用?Python Comment.email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.email方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import email [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
示例2: article
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import email [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))
示例3: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import email [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())
示例4: createComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import email [as 别名]
def createComment(request, blog_key):
form = CommentForm(request.POST)
if form.is_valid():
comment = Comment()
comment.blog = Blog.get(blog_key)
comment.author = form.cleaned_data["author"]
comment.email = form.cleaned_data["email"]
comment.content = form.cleaned_data["content"]
comment.put()
context = Context({"blog": comment.blog, "comment": comment, "admin": admin()})
template = loader.get_template("blogs/_comment.html")
reponse = dict(msg=1, data=template.render(context))
return HttpResponse(json.dumps(reponse), mimetype="application/json")
else:
data = ""
for errItem in form.errors.items():
errTitle = str(errItem[0])
errContent = errItem[1].as_text()
if data == "":
data = "<div>" + errTitle + ":" + errContent + "</div>"
else:
data = "\n<div>" + errTitle + ":" + errContent + "</div>"
reponse = dict(msg=0, data=data)
return HttpResponse(json.dumps(reponse), mimetype="application/json")
示例5: save_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import email [as 别名]
def save_comment():
msg = "Comment not saved."
try:
nome = request.form['name']
email = request.form['email']
texto = request.form['content']
post_id = request.form['post_id']
comentario = Comment()
comentario.name = nome
comentario.email = email
comentario.content = texto
comentario.display = False
comentario.date_created = datetime.today()
comentario.post_id = post_id
db.session.add(comentario)
db.session.commit()
msg = "Comentário enviado! Obrigado!"
except:
db.session.rollback()
traceback.print_exc()
#raise
data = {}
data['message'] = msg
return jsonify(data)