def add_comment_to_review(review_id): form = CommentForm(request.form) if form.validate(): comment = cgi.escape(form.comment.data) # add comment replyer_id = session['user_id'] replyee_id = get_comment_replyee_id(comment) # check if @people exist if replyee_id != -1: comment = rebuild_comment(comment, replyee_id) new_comment_id = Comment.add_comment_to_review(review_id, replyer_id, comment) Review.add_comment_num(review_id) # add inform review_user_id = Review.get_review(review_id)['UserID'] inform_title = build_review_inform_title(replyer_id, review_id) # if the review not add by me if replyer_id != review_user_id: Inform.add(replyer_id, review_user_id, inform_title, comment) # if replyee exist, # and the topic not add by me, # and not review_user_id, because if so, the inform has already been sended above if replyee_id != -1 and replyee_id != replyer_id and replyee_id != review_user_id: Inform.add(replyer_id, replyee_id, inform_title, comment) return redirect(url_for('single_review', review_id=review_id) + "#" + str(new_comment_id)) else: return redirect(url_for('single_review', review_id=review_id))
def informs(): check_login() # pagination num_per_page = 10 page = int(request.args['page'] if 'page' in request.args else 1) informs = Inform.get_informs(session['user_id'], page, num_per_page) for i in informs: i['Time'] = time_diff(i['Time']) # page paras informs_num = Inform.get_informs_num(session['user_id']) #return str(informs_num) total_page = int(math.ceil(informs_num / num_per_page)) pre_page = (page - 1) if page > 1 else 1 if total_page == 0: next_page = 1 elif page < total_page: next_page = page + 1 else: next_page = total_page new_informs_num = Inform.get_new_informs_num(session['user_id']) Inform.update_check_inform_time(session['user_id']) return render_template('informs.html', informs=informs, new_informs_num=new_informs_num, page=page, total_page=total_page, pre_page=pre_page, next_page=next_page)
def add_comment_to_topic(topic_id): form = CommentForm(request.form) if form.validate(): comment = cgi.escape(form.comment.data) # add comment replyer_id = session['user_id'] replyee_id = get_comment_replyee_id(comment) # check if @people exist if replyee_id != -1: comment = rebuild_comment(comment, replyee_id) new_comment_id = Comment.add_comment_to_topic(topic_id, replyer_id, comment) # plus comment num by 1 Topic.add_comment_num(topic_id) # add inform topic_user_id = Topic.get_topic(topic_id)['UserID'] inform_title = build_topic_inform_title(replyer_id, topic_id) # if the topic not add by me if replyer_id != topic_user_id: Inform.add(replyer_id, topic_user_id, inform_title, comment) # if replyee exist, # and the topic not add by me, # and not topic_user_id, because if so, the inform has already been sended above if replyee_id != -1 and replyee_id != replyer_id and replyee_id != topic_user_id: Inform.add(replyer_id, replyee_id, inform_title, comment) return redirect(url_for('single_topic', topic_id=topic_id) + "#" + str(new_comment_id)) else: return redirect(url_for('single_topic', topic_id=topic_id))
def inject_vars(): return dict( douban_login_url=config.DOUBAN_LOGIN_URL, # douban oauth url admin_id=config.ADMIN_ID, # admin id informs_num=Inform.get_new_informs_num(session['user_id']) if 'user_id' in session else 0) # new informs num
def inject_vars(): return dict( douban_login_url = config.DOUBAN_LOGIN_URL, # douban oauth url admin_id = config.ADMIN_ID, # admin id informs_num = Inform.get_new_informs_num(session['user_id']) if 'user_id' in session else 0) # new informs num