Python Comment.status方法代码示例

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


Python Comment.status方法代码示例

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

示例1: _upsert_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import status [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

本文标签属性:

示例:示例志愿表

代码:代码是什么

Python:python基础教程

上一篇:C++ platform_driver_probe函数代码示例
下一篇:C++ AB函数代码示例

为您推荐