本文整理汇总了Python中blog.forms.CommentForm.get_comment_object方法的典型用法代码示例。如果您正苦于以下问题:Python CommentForm.get_comment_object方法的具体用法?Python CommentForm.get_comment_object怎么用?Python CommentForm.get_comment_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.forms.CommentForm
的用法示例。
在下文中一共展示了CommentForm.get_comment_object方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_coment
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import get_comment_object [as 别名]
def post_coment(request):
data = request.POST.copy()
ctype = data.get("content_type")
object_pk = data.get("object_pk")
if ctype is None or object_pk is None:
return CommentPostBadRequest("Missing content_type or object_pk field.")
try:
model = models.get_model(*ctype.split(".", 1))
target = model._default_manager.get(pk=object_pk)
except (TypeError,AttributeError,ObjectDoesNotExist):
return CommentPostBadRequest(
"No object matching content-type %r and object PK %r exists." % \
(escape(ctype), escape(object_pk)))
form = CommentForm(target, data=data)
if form.security_errors():
return CommentPostBadRequest(
"The comment form failed security verification: %s" % \
escape(str(form.security_errors())))
if form.errors:
message = None
for field in ['author', 'email', 'content', 'url']:
if field in form.errors:
if form.errors[field][0]:
message = '[%s] %s' % (field.title(), form.errors[field][0].capitalize())
break
return render_to_response('400-debug.html', {'why': message})
comment = form.get_comment_object()
comment.ip_address = request.META.get("REMOTE_ADDR", None)
comment.useragent=request.META.get('HTTP_USER_AGENT','unknown')
reg = re.compile(u"[\u4e00-\u9fa5]")
if reg.findall(comment.content):
comment.is_public=True
else:
comment.is_public=False
comment.save()
#send email
signals.comment_was_submit.send(
sender = comment.__class__,
comment = comment
)
response = HttpResponseRedirect(comment.get_absolute_url())
try:
response.set_cookie('author', comment.author, max_age = 31536000)
response.set_cookie('email', comment.email, max_age = 31536000)
response.set_cookie('weburl', comment.weburl, max_age = 31536000)
except:
pass
return response