def on_get(self, req, resp, token): site = self.get_site(token) params = json.load(req.stream) page = int(params.get('page', 0)) num = int(params.get('num', config.DEFAULT_PAGE_NUM)) fid = int(params.get('fid', -1)) if page < 1 or num < 0 or fid < 0: raise falcon.HTTPBadRequest(config.HTTP_400, 'invalid params') f_comment = get_comment_cached(site, fid) if not f_comment: raise falcon.HTTPNotFound() comments = get_comments_by_fid(site, f_comment.count, page, num, fid = f_comment.id) resp.status = falcon.HTTP_200 resp.stream = ijson.dump([self.render_comment(comment) for comment in comments])
def on_delete(self, req, resp, token): site = self.get_site(token) params = json.load(req.stream) id = int(params.get('id', 0)) if not id: raise falcon.HTTPBadRequest(config.HTTP_400, 'invalid params') comment = get_comment_cached(site, id) if not comment: raise falcon.HTTPNotFound() try: delete_comment(site, comment) except Exception: logger.exception('delete') raise falcon.HTTPInternalServerError(config.HTTP_500, 'delete comment failed') resp.status = falcon.HTTP_200