def topic_detail(topic_id, page): topic = Topic.query.get(topic_id) if not current_user.in_team(topic.project.team_id): abort(404) form = CommentForm(current_user, topic, request.form.getlist('attachment')) items_per_page = 20 if form.validate_on_submit(): comment = form.saveTopic() if comment is not None: flash(u'保存成功') pagination = Topic.query.filter_by(class_type='topic', is_comment=1, class_id=topic.id).order_by( "topic.created_at asc").paginate(page, items_per_page) return redirect( url_for('topic_detail', topic_id=topic_id, page=pagination.pages, _anchor='comment%i' % comment.id)) else: flash(u'保存失败,请联系管理员', 'error') pagination = Topic.query.filter_by(class_type='topic', is_comment=1, class_id=topic.id).order_by( "topic.created_at asc").paginate(page, items_per_page) return render_template('project/topic_detail.html', project=topic.project, topic=topic, form=form, pagination=pagination)