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


Python Comment.article方法代码示例

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


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

示例1: lire_article

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import article [as 别名]
def lire_article(request, slug):
    """
    Affiche un article complet, sélectionné en fonction du slug
    fourni en paramètre
    """
    article = get_object_or_404(Article, slug=slug)
    comments = Comment.objects.filter(article=article)
    
    if request.method == 'POST':
        form = CommentForm(request.POST)
        
        if form.is_valid():
            
            # ajouter la relation avec l'article
            comment = Comment()
            comment.pseudo = form.cleaned_data['pseudo']
            comment.email = form.cleaned_data['email']
            comment.contenu = form.cleaned_data['contenu']
            comment.article = article
            
            comment.save()
            
            renvoi = True 
    else:
            form = CommentForm()

    return render(request, 'blog/lire_article.html', locals())
开发者ID:VincentMardon,项目名称:django_blog,代码行数:29,代码来源:views.py

示例2: get_article

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import article [as 别名]
def get_article(request,slug):
    try:
        article=Article.objects.get(slug=slug)
    except ObjectDoesNotExist:
        return HttpResponseRedirect('/')

    try:
        comments=Comment.objects.filter(article=article).order_by('-date','-id')        
    except ObjectDoesNotExist:
        comments=None
   
    if request.method == 'POST': 
        form = CommentForm(request.POST, **{'article':article,'ip':request.META['REMOTE_ADDR'],})
        if form.is_valid(): 
            comment=Comment()
            comment.comment = form.cleaned_data['comment']
            comment.article = article
            if request.user.is_authenticated():
                comment.user = request.user
            comment.ip=request.META['REMOTE_ADDR']
            comment.save()
            return HttpResponseRedirect('/'+article.slug) 
    else:
        form = CommentForm() 

    
    return render_to_response('blog/article.html', {
        'form': form,
        'article': article,
        'comments':comments,
    },context_instance=RequestContext(request))
开发者ID:glebkolyagin,项目名称:superblog,代码行数:33,代码来源:views.py

示例3: comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import article [as 别名]
def comment(request, article_id):
		if not request.POST['author'] or not request.POST['text']:
			request.message = "vous avez oubliez une partie du commentaire non?"
	   		return detail(request, article_id)
	   	else:
	   		request.message = "commentaire enregistre!"
		comment = Comment()
		comment.author=request.POST['author']
		comment.text = request.POST['text']
		comment.date =  timezone.now()
		comment.article = Article.objects.get(id = article_id)
		comment.save()
	   	return detail(request, article_id)
开发者ID:kizdolf,项目名称:dkblog,代码行数:15,代码来源:views.py

示例4: _upsert_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import article [as 别名]
def _upsert_comment(comment):
    """
        操作类型:
            create:创建评论
            approve:通过评论
            spam:标记垃圾评论
            delete:删除评论
            delete-forever:彻底删除评论
    """
    action = comment.get('action', '')
    meta = comment.get('meta', None)
    if meta and isinstance(meta, dict):
        from blog.models import Article, Comment
        a_id = meta.get('thread_key')
        try:
            if action == 'create':
                try:
                    article = Article.objects.get(id=int(a_id))
                except (Article.DoesNotExist, TypeError, ValueError) as e:
                    print 'Article does not exist, ID: %s, error: %s' % (a_id, e)
                    return
                c = Comment()
                c.article = article
                parent_id = meta.get('parent_id', '0')
                parent_c = Comment.objects.filter(duoshuo_id=parent_id)
                c.parent = None if parent_id == '0' or parent_c.count() == 0 else parent_c[0]

                c.duoshuo_id = meta.get('post_id', '')
                c.duoshuo_user_id = comment.get('user_id', '')
                c.author = meta.get('author_name', '')
                c.author_email = meta.get('author_email', '')
                c.author_website = meta.get('author_url', '')
                c.author_ip = meta.get('ip', '')
                c.comment_date = timestamp2datetime(comment.get('date', None), convert_to_local=True) or datetime.datetime.now()
                c.content = _clean_content(meta.get('message', ''))
                c.author_agent = ''
                status = meta.get('status', '')
                c.status = COMMENT_STATUS.APPROVED if status == 'approved' else (COMMENT_STATUS.NOT_REVIEWED if status == 'pending' else COMMENT_STATUS.REJECTED)
                c.sync_status = 0
                c.save()
                print 'Create comment, article ID: %s, comment ID: %s' % (a_id, c.id)
            elif action == 'approve':
                Comment.objects.filter(duoshuo_id__in=meta).update(status=COMMENT_STATUS.APPROVED)
            elif action == 'spam':
                Comment.objects.filter(duoshuo_id__in=meta).update(status=COMMENT_STATUS.REJECTED)
            elif action in ('delete', 'delete-forever'):
                Comment.objects.filter(duoshuo_id__in=meta).update(hided=True, status=COMMENT_STATUS.REJECTED)
        except Exception, e:
            print 'update article comment failed, exception: %s, comment: %s' % (e, comment)
开发者ID:qiuzhangcheng,项目名称:GeekBlog,代码行数:51,代码来源:sync_views_and_comment_count.py

示例5: show

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import article [as 别名]
def show(request,uid=-1,aid=-1,*arg,**kwarg):
	uid=int(uid)
	userInfos=common.Users(request,uid)

	guestBlog=userInfos["guestblog"]
	try:
		myModules=guestBlog.modules.split(",")
	except:
		myModules = ''.split(',')
	moduleParams={}
	for myModule in myModules:
		moduleParams.setdefault(myModule,{"uid":uid})

	moduleList=modules.GetModuleList(moduleParams)
	

	articleInfo=Article.objects.get(id=aid)

	

	template = 'default'
	if request.POST.has_key('ok'):
		username = utility.GetPostData(request,'username')
		content = utility.GetPostData(request,'content')

		comment=Comment()
		comment.article=articleInfo
		comment.content=content
		comment.user_id=userInfos["currentuser"].id
		comment.username=username
		comment.createtime=datetime.datetime.now()
		comment.save()

		articleInfo.comments+=1

		if guestBlog:
			guestBlog=userInfos["guestblog"]
			guestBlog.comments+=1
			guestBlog.save()
			template = guestBlog.template

	commentList=Comment.objects.filter(article_id=aid)

	#更新文章浏览量
	articleInfo.views+=1
	articleInfo.save()

	return utility.my_render_to_response(request,"Skins/"+template+"/show.html",locals())
开发者ID:xf22001,项目名称:myblog,代码行数:50,代码来源:viewsarticle.py

示例6: blog_show_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import article [as 别名]
def blog_show_comment(request, blog_id):
    blog = Article.objects.get(pk=blog_id)
    if request.method == 'POST':
        name = request.POST['name']
        content = request.POST['content']
        print name, content
        try:
            new_comment = Comment()
            new_comment.article = blog
            new_comment.name = name
            new_comment.content = content
            new_comment.save()
            import datetime
            date = unicode(datetime.datetime.now())[0:-13]                     #TODO datatype优化
            date = u' ' + date
            content = unicode(escape(content))
            data_returned = {"name": name, "content": content, "date": date}
        except Exception, ex:
            print ex
            return HttpResponse("false")

        return JsonResponse(data_returned)
开发者ID:bricksfx,项目名称:django_self_blog,代码行数:24,代码来源:views.py


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