当前位置: 首页>>代码示例>>Python>>正文


Python CommentForm.security_errors方法代码示例

本文整理汇总了Python中blog.forms.CommentForm.security_errors方法的典型用法代码示例。如果您正苦于以下问题:Python CommentForm.security_errors方法的具体用法?Python CommentForm.security_errors怎么用?Python CommentForm.security_errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blog.forms.CommentForm的用法示例。


在下文中一共展示了CommentForm.security_errors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_coment

# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import security_errors [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
开发者ID:Magnil,项目名称:logpress,代码行数:57,代码来源:index.py


注:本文中的blog.forms.CommentForm.security_errors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。