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
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