def thread_show(art_id, thr_id): form = CommentForm() likeform = LikeForm() artist = Artist.query.filter_by(id=art_id).first_or_404() thread = Thread.query.filter_by(id=thr_id).first_or_404() thread.uni_content = unicode(escape(thread.content)).replace("\r\n", "<br />") # 查询评论 type_id: 1-问题,2-曲谱,3-二手交易,4-活动,5-艺人 comments_select = comments_query(5, thr_id) if current_user.is_anonymous() or current_user.id != thread.uid: thread.hot = thread.hot + 1 db.session.commit() is_like = None if current_user.is_authenticated(): is_like = Like.query.filter_by(uid=current_user.id).filter_by(like_type=2)\ .filter_by(like_id=art_id).first() if request.method == 'POST' and form.validate_on_submit(): comment = Comment() comment.save(form, current_user.id, 5, thr_id) thread.comments_num = thread.comments_num + 1 db.session.commit() comments_select = comments_query(5, thr_id) return redirect(url_for('artists.thread_show', art_id=art_id, thr_id=thr_id)) #return render_template('artists/comments_ajax.html', comments=comments_select, thread=thread) return render_template('artists/thread_show.html', comments=comments_select, thread=thread, form=form,\ artist=artist, likeform=likeform, is_like=is_like)
def question_show(id): form = CommentForm(formdata=request.values) question = Question.query.filter_by(id=id).first_or_404() question.uni_content = unicode(escape(question.content)).replace("\r\n", "<br />") comments = comments_query(1, id) dic_codes = dict([(code.id,code.code_name) for code in Dic_code.query.all()]) big_cates = Dic_code.query.filter_by(parent_id=2).all() for big_cate in big_cates: big_cate.children = Dic_code.query.filter(Dic_code.parent_id == big_cate.type_id).order_by(Dic_code.id) if current_user.is_anonymous() or current_user.id != question.uid: question.hot = question.hot + 1 db.session.commit() if request.method == 'POST' and form.validate_on_submit(): comment = Comment() comment.save(form, current_user.id, 1, id) question.modify_time = datetime.now() question.comments_num = question.comments_num + 1 db.session.commit() return redirect(url_for('questions.question_show', id=id)) return render_template('questions/question_show.html', question=question, big_cates=big_cates, \ dic_codes=dic_codes, comments=comments, form=form)
def tab_show(id): form = CommentForm(formdata=request.values) likeform = LikeForm() tab = Tab.query.filter_by(id=id).first_or_404() content = unicode(escape(tab.content)).replace(' ', ' ').replace('\r\n', '<br />') if tab.tabs_type == 5: tab.tab_imgs = tab.tabs_path.split('|') dic_codes = dict([(code.id,code.code_name) for code in Dic_code.query.all()]) if tab.instrument != 13: instrument = dic_codes[tab.instrument] + u'谱' else: instrument = u'乐谱' # 查询评论 type_id: 1-问题,2-曲谱,3-二手交易,4-活动,5-艺人 comments = comments_query(2, id) if current_user.is_anonymous() or current_user.id != tab.uid: tab.hot = tab.hot + 1 db.session.commit() is_like = None if current_user.is_authenticated(): is_like = Like.query.filter_by(uid=current_user.id).filter_by(like_type=1)\ .filter_by(like_id=id).first() if request.method == 'POST' and form.validate_on_submit(): comment = Comment() comment.save(form, current_user.id, 2, id) db.session.commit() return redirect(url_for('tabs.tab_show', id=id)) return render_template('tabs/tab_show.html', form=form, tab=tab, comments=comments, content=content,\ is_like=is_like, likeform=likeform, instrument=instrument)
def threads_list(id): form = ThreadForm() likeform = LikeForm() artist = Artist.query.filter_by(id=id).first_or_404() threads = Thread.query.filter_by(artist=id).order_by(Thread.create_time.desc()) dic_codes = dict([(code.id,code.code_name) for code in Dic_code.query.all()]) if request.method == 'POST' and form.validate_on_submit(): thread = Thread() thread.save(form, current_user.id, id) artist.threads_num = artist.threads_num + 1 db.session.commit() threads = Thread.query.filter_by(artist=id).all() return redirect(url_for('artists.threads_list', id=id)) page = request.args.get('page') if not page or int(page) < 1: page = 1 threads = threads.paginate(int(page), PER_PAGE, True) for thread in threads.items: thread.comments = comments_query(5, thread.id) is_like = None if current_user.is_authenticated(): is_like = Like.query.filter_by(uid=current_user.id).filter_by(like_type=2)\ .filter_by(like_id=id).first() return render_template('artists/threads_list.html', form=form, artist=artist, \ dic_codes=dic_codes, threads=threads, likeform=likeform, is_like=is_like)
def trade_show(id): form = CommentForm(formdata=request.values) thing = Thing.query.filter_by(id=id).first() thing.thing_content = unicode(escape(thing.content)).replace(' ', ' ').replace('\r\n', '<br />') comments = comments_query(4, id) if current_user.is_anonymous() or current_user.id != thing.uid: thing.things_hot = thing.things_hot + 1 db.session.commit() if request.method == 'POST' and form.validate_on_submit(): comment = Comment() comment.save(form, current_user.id, 4, id) db.session.commit() return redirect(url_for('trade.trade_show', id=id)) return render_template('trade/trade_show.html', form=form, thing=thing, comments=comments)