本文整理汇总了Python中blog.forms.CommentForm.get_comment方法的典型用法代码示例。如果您正苦于以下问题:Python CommentForm.get_comment方法的具体用法?Python CommentForm.get_comment怎么用?Python CommentForm.get_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.forms.CommentForm
的用法示例。
在下文中一共展示了CommentForm.get_comment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_form_context
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import get_comment [as 别名]
def get_form_context(request, entry):
"""
Post a comment.
"""
# Fill out some initial data fields from an authenticated user, if present
initial = { }
if request.user.is_authenticated():
initial["name"] = request.user.get_full_name()
initial["email"] = request.user.email
# If there are errors or if we requested a preview show the comment
if request.method == 'POST':
form = CommentForm(entry, request.POST, initial=initial)
if form.is_valid():
# Create the comment
comment = form.get_comment()
comment.ip_address = request.META.get("REMOTE_ADDR", None)
if request.user.is_authenticated():
comment.user = request.user
# Signal that the comment is about to be saved
responses = signals.comment_will_be_posted.send(
sender = comment.__class__,
comment = comment,
request = request
)
for (receiver, response) in responses:
if response == False:
return django_comments.CommentPostBadRequest(
"comment_will_be_posted receiver %r killed the comment" % receiver.__name__)
comment.save()
# Save the comment and signal that it was saved
signals.comment_was_posted.send(
sender = comment.__class__,
comment = comment,
request = request
)
# Feedback --> check in the template for 'commented'. Users can comment
# without having to log in so request.user.message_set can't be used
return {
'commented' : True,
# Return a fresh form
'form': CommentForm(entry, initial=initial)
}
else:
if request.user.is_authenticated():
messages.error(request, _(u"Your comment could not be posted. Please correct the errors below."))
else:
form = CommentForm(entry, initial=initial)
return { 'commented': False, 'form': form }