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


Python Comment.save方法代码示例

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


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

示例1: create

# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import save [as 别名]
def create(parameters):
    comment = Comment(Comment.cxn, "comments", parameters)
    try:
        comment.save()
        attributes_to_render = comment.attributes
        attributes_to_render.update({"id": comment.id})
        template = open('./templates/comments/show.html').read()
        attributes_to_render.update({"html": TemplateEngine(template, attributes_to_render).render_partial()})
        return json.dumps(attributes_to_render)
    except ValidationError as ve:
        response = {"status": 422, "errors": ve.messages}
        return json.dumps(response)
    except Exception as e:
        print(str(e))
        response = {"status": 500, "errors": [str(e)]}
        return json.dumps(response)
开发者ID:zackmdavis,项目名称:Wires,代码行数:18,代码来源:comments_controller.py

示例2: sleep

# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import save [as 别名]
                                comment.reply(commandResponse)

                girmRequestsToFind = re.findall(r'\[\s*girm\s*([\d\-,\s]+)\s*\\?\](?im)(?!\()', comment.body)
                if girmRequestsToFind:
                    requestIsValid,commandResponse = girmResponse.getResponse(girmRequestsToFind)
                    if requestIsValid:
                        try:
                            comment.reply(commandResponse)
                        except praw.exceptions.APIException as e:
                            if e.error_type == "RATELIMIT":
                                logger.warning("Sleeping 90 seconds due to RateLimitExceed ")
                                sleep(90)
                                comment.reply(commandResponse)

                try:
#                    db.connection().enable_query_log()
                    logger.info("Cleaning database of old comments")
                    db.table('comments').where('utcTime', '<', time.time() - 31*24*60*60).delete()
                    dbComment = Comment()
                    dbComment.commentId = comment.id
                    dbComment.utcTime = time.time()
                    dbComment.save()
                    logger.info("Inserting comment %s by user %s into database" % (comment.id, comment.author.name))
                except:
                    logger.critical("Database insert for comment %s by user %s failed." % (comment.id, comment.author.name),sys.exc_info()[0],"x")
                    exit()

    except requests.exceptions.HTTPError:
        logger.error("HTTP Error: waiting 5 minutes to retry"+sys.exc_info()[0],"e")
        sleep(5*60)
开发者ID:konohitowa,项目名称:catebot,代码行数:32,代码来源:catebot.py

示例3: post

# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import save [as 别名]
    def post(self, slug=None):
        useajax = self.param('useajax') == '1'

        name = self.param('author')
        email = self.param('email')
        url = self.param('url')

        key = self.param('key')
        content = self.param('comment')
        checknum = self.param('checknum')
        checkret = self.param('checkret')

        if not self.is_login:
            if not self.request.cookies.get('comment_user', ''):

                try:
                    import app.gbtools as gb
                    if eval(checknum) != int(gb.stringQ2B(checkret)):
                        if useajax:
                            self.write(simplejson.dumps((False, -102, _('Your check code is invalid .'))))
                        else:
                            self.error(-102, _('Your check code is invalid .'))
                        return
                except:
                    if useajax:
                        self.write(simplejson.dumps((False, -102, _('Your check code is invalid .'))))
                    else:
                        self.error(-102, _('Your check code is invalid .'))
                    return

        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, entry=Entry.get(key))
            if url:
                try:
                    comment.weburl = url
                except:
                    comment.weburl = 'http://' + url

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

            logging.info('info:' + info_str)

            cookiestr = 'comment_user=%s;expires=%s;domain=%s;path=/' % (info_str, (datetime.now()
                     + timedelta(days=100)).strftime('%a, %d-%b-%Y %H:%M:%S GMT'), '')
            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'))))
            else:

                self.redirect(self.referer)
开发者ID:oldhu,项目名称:micolog-oldhu,代码行数:66,代码来源:blog.py


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