def post(self, *args, **kwargs): comment = self.get_argument("comment", "") user_re = re.compile(r"@(\S{3,19}) (.*)") try: foruser = user_re.search(comment).group(1) if not User.exist(foruser): foruser = "" else: comment = user_re.search(comment).group(2) except Exception as e: foruser = "" article_key = self.get_argument("article_key", "") user = self.current_user() if user is not None: username = user.username else: username = "******" if user is not None and user.level == 0: self.messages.error("您暂时无法评论!") elif Comment.num_lim(username): self.messages.error("评论过多,暂时无法评论,请联系管理员!") elif comment != "": Comment.new(username, foruser, comment, article_key) self.messages.success("评论成功!") self.redirect("/spider/" + article_key)
def create_comment(self, params, comment_type): if comment_type == 'txt': if not params.get('content', False): raise HTTPError(403, 'there is not data') comment = Comment.new(**params) if comment_type == 'audio': audio = hqby.audio.get_temp_audio(params['audio_id']) info = hqby.audio.move_temp_audio( audio, configs['audio_base_path'], configs['audio_base_url'], hqby.audio.id_to_subdir(params['topic_id']) ) #info['src'] = info['src'].encode('utf-8') info['audio_len'] = audio['len'] info['type'] = audio['type'] params['content'] = json.dumps(info) del params['audio_id'] comment = Comment.new(**params) return comment