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


Python CommentForm.get_comment方法代码示例

本文整理汇总了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 }
开发者ID:nielsvanoch,项目名称:django-blog,代码行数:58,代码来源:views.py


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