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


Python Comment.parent方法代码示例

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


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

示例1: _upsert_comment

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

示例2: POST

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import parent [as 别名]
    def POST(self,slug=None):
        useajax=self.param('useajax')=='1'
        logging.debug('+++++++++++++++++++++++1')
        name=self.param('author')
        email=self.param('email')
        url=self.param('url')

        key=self.param('key')
        content=self.param('comment')
        parent_id=self.paramint('parentid',0)
        reply_notify_mail=self.parambool('reply_notify_mail')

        sess=Session(self,timeout=180)
        if not self.is_login:
            #if not (self.request.cookies.get('comment_user', '')):
            #try:
            if 1:
                check_ret=True
                if self.blog.comment_check_type in (1,2)  :
                    checkret=self.param('checkret')
                    check_ret=(int(checkret) == sess['code'])
                elif self.blog.comment_check_type ==3:
                    import app.gbtools as gb
                    checknum=self.param('checknum')
                    checkret=self.param('checkret')
                    check_ret=eval(checknum)==int(gb.stringQ2B( checkret))

                if not check_ret:
                    if useajax:
                        self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False))
                    else:
                        self.error(-102,_('Your check code is invalid .'))
                    return
            #except:
            if 0:
                if useajax:
                    self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False))
                else:
                    self.error(-102,_('Your check code is invalid .'))
                return
        sess.invalidate()
        content=content.replace('\n','<br />')
        content=myfilter.do_filter(content)
        name=cgi.escape(name)[:20]
        url=cgi.escape(url)[:100]
        if not (name and email and content):
            if useajax:
                self.write(simplejson.dumps((False,-101,_('Please input name, email and comment .'))))
            else:
                self.error(-101,_('Please input name, email and comment .'))
        else:
            comment=Comment(author=name,
                            content=content,
                            email=email,
                            reply_notify_mail=reply_notify_mail,
                            entry=Entry.get(key))
            if url:
                try:
                    if not url.lower().startswith(('http://','https://')):
                        url = 'http://' + url
                    comment.weburl=url
                except:
                    comment.weburl=None

            #name=name.decode('utf8').encode('gb2312')


            info_str='#@#'.join([urlencode(name),urlencode(email),urlencode(url)])

             #info_str='#@#'.join([name,email,url.encode('utf8')])
            cookiestr='comment_user=%s;expires=%s;path=/;'%( info_str,
                       (datetime.now()+timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT")
                       
                       )
            comment.ip=self.request.remote_addr

            if parent_id:
                comment.parent=Comment.get_by_id(parent_id)

            comment.no=comment.entry.commentcount+1
            #try:
            if 1:
                comment.save()
                memcache.delete("/"+comment.entry.link)

                self.response.headers.add_header( 'Set-Cookie', cookiestr)
                if useajax:
                    comment_c=self.get_render('comment',{'comment':comment})
                    self.write(simplejson.dumps((True,comment_c.decode('utf8')),ensure_ascii = False))
                else:
                    self.redirect(self.referer+"#comment-"+str(comment.key().id()))

                comment.entry.removecache()
                memcache.delete("/feed/comments")
            #except:
            if 0:
                if useajax:
                    self.write(simplejson.dumps((False,-102,_('Comment not allowed.'))))
                else:
                    self.error(-102,_('Comment not allowed .'))
开发者ID:zy-sunshine,项目名称:sunblackshineblog,代码行数:102,代码来源:views.py


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