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


Python Comment.user_name方法代码示例

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


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

示例1: comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import user_name [as 别名]
def comment(request, id):
    """
    Add a comment to blog
    """
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            comment = Comment()
            comment.comment = data['comment']
            comment.blog_id = id
            comment.user_name = data['user_name']
            comment.email = data['email']
            comment.source_address = request.META['REMOTE_ADDR']# '192.168.2.8'
            comment.create_date = datetime.datetime.now()
            comment.save()
            blog = Blog.objects.get(id=id)
            if blog.comment_count is None:
                blog.comment_count = 0
            blog.comment_count += 1
            blog.save()
            if request.user.is_authenticated():
                return HttpResponseRedirect('/adminshow/%s/' % id)
            else:
                return HttpResponseRedirect('/show/%s/' % id)
        else:
            blog = Blog.objects.get(id=id)
            comments = Comment.objects.filter(blog_id=id)
            return render_to_response('artical.html', {'blog' : blog, 'comments' : comments, 'form' : form}, context_instance=RequestContext(request, processors=[new_blog, blog_group]))
    else:
        return HttpResponseRedirect('/show/%s/' % id)
开发者ID:kelvinfang,项目名称:juncheefamily,代码行数:33,代码来源:views.py

示例2: comment_create

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import user_name [as 别名]
def comment_create(request, post_slug):

    try:
        post = Post.objects.get(slug=post_slug)
    except Post.DoesNotExist:
        raise Http404()

    if "content_raw" not in request.POST:
        return redirect(
            reverse("blog:post_detail", args=[post.category.name, post_slug]))

    if not post.published and not request.user.is_superuser:
        raise PermissionDenied()

    comment = Comment()
    if request.user.is_authenticated():
        comment.user = request.user
    else:
        if ('user_name' not in request.POST or
                'user_email' not in request.POST):
            return redirect(
                reverse(
                    "blog:post_detail", args=[post.category.name, post_slug]))

        comment.user_name = request.POST['user_name']
        comment.user_email = request.POST['user_email']

    comment.content_raw = request.POST['content_raw']
    comment.post = post
    comment.save()

    send_email_notification.delay(
        title=u'Новый коментарии',
        message=u'Новый коменатрии \n{0}\n{1}'.format(
            reverse('blog:post_detail', args=[post.category.name, post_slug]),
            datetime.datetime.now()))

    return redirect(
        reverse("blog:post_detail", args=[post.category.name, post_slug]))
开发者ID:ilnurgi,项目名称:website,代码行数:41,代码来源:views.py

示例3: post

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import user_name [as 别名]
 def post(self,*args,**kwargs):
     self.object = self.get_object()
     request = self.request
     context = self.get_context_data(object=self.object)
     comment_f = myforms.CommentForm(self.request.POST)
     if comment_f.is_valid():
         # (1,2,3).append(5)
         comment = Comment()
         post_data = comment_f.cleaned_data
         comment.text = post_data['text']
         comment.reply_to = post_data['reply_to']
         comment.email_id = post_data['email_id']
         comment.comment_for = self.object
         comment.user_name = post_data['user_name']
         comment.user_url = post_data['user_url']
         comment.user_ip = request.META['REMOTE_ADDR']
         comment.user_agent = request.META['HTTP_USER_AGENT']
         comment.is_public = getattr(settings, 'AUTO_APPROVE_COMMENTS',
                                     True)
         comment.save()
         return HttpResponseRedirect('#comment-%s' % comment.pk)
     context.update({'comment_form': comment_f})
     return self.render_to_response(context)
开发者ID:cjhgo,项目名称:cjhang,代码行数:25,代码来源:views.py


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