예제 #1
0
파일: delete.py 프로젝트: CMGS/ymir
    def on_delete(self, req, resp, token):
        site = self.get_site(token)
        params = json.load(req.stream)

        ip = params.get("ip", None)
        tid = int(params.get("tid", -1))
        if not ip:
            raise falcon.HTTPBadRequest(config.HTTP_400, "invalid params")

        try:
            # Because this method will update comment table
            # and Father comment if fid is not 0
            # That's why this method tooooo slow for large data
            comments = get_comments_by_ip(site, ip, tid)
            f_comments = []
            for comment in comments:
                if comment.fid != 0:
                    delete_comment(site, comment)
                    continue
                f_comments.append(comment)
            for comment in f_comments:
                delete_comment(site, comment)
        except Exception:
            logger.exception("delete")
            raise falcon.HTTPInternalServerError(config.HTTP_500, "delete comment failed")

        resp.status = falcon.HTTP_200
예제 #2
0
파일: enhance.py 프로젝트: CMGS/ymir
    def on_get(self, req, resp, token):
        site = self.get_site(token)
        params = json.load(req.stream)

        ip = params.get('ip', None)
        tid = int(params.get('tid', -1))
        if not ip:
            raise falcon.HTTPBadRequest(config.HTTP_400, 'invalid params')

        comments = get_comments_by_ip(site, ip, tid)

        resp.status = falcon.HTTP_200
        resp.stream = ijson.dump([self.render_comment(comment) for comment in comments])