def edit_topic(topic_id): topic = Topic.query.get_or_404(topic_id) if current_user != topic.author and current_user != topic.group.admin and not current_user.can( 'MODERATE'): abort(403) #除了主题的author、主题所在组的管理员或者协管员,都不能编辑主题 form = PostForm() if form.validate_on_submit(): topic.name = form.title.data topic.body = form.body.data if form.publish.data: topic.saved = False db.session.commit() if form.notice.data and not current_user.is_noticing(topic): current_user.notice(topic) flash('主题已发表', 'success') return redirect(url_for('main.show_topic', topic_id=topic.id)) elif form.save.data: if topic.get_last_post(): flash('已有回帖,不允许保存。', 'warning') return redirect_back() else: topic.saved = True topic.top = False db.session.commit() flash('主题已保存', 'success') return redirect(url_for('user.draft_topic')) elif form.save1.data: topic.saved = True topic.top = False db.session.commit() flash('请上传附件', 'info') return redirect(url_for('.upload_topic', topic_id=topic.id)) form.title.data = topic.name form.body.data = topic.body return render_template('main/edit_topic.html', form=form, topic=topic)
def unnotice(topic_id): topic = Topic.query.get_or_404(topic_id) if not current_user.is_noticing(topic): flash('还未订阅此主题', 'info') current_user.unnotice(topic) flash('已取消订阅此主题', 'success') return redirect_back()
def notice(topic_id): topic = Topic.query.get_or_404(topic_id) if current_user.is_noticing(topic): flash('此主题已订阅过', 'info') return redirect_back() current_user.notice(topic) flash('订阅成功', 'success') if current_user != topic.author and topic.author.receive_notice_notification: push_notice_notification(topic=topic, user=current_user) return redirect_back()
def edit_post(post_id): post = Post.query.get_or_404(post_id) if post.deleted and not current_user.can('MODERATE'): abort(404) if current_user != post.author and current_user != post.topic.group.admin and not current_user.can( 'MODERATE'): abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.body = form.body.data if form.publish.data: post.saved = False db.session.commit() if post.topic.receivers: for notice in post.topic.receivers: send_new_post_email(receiver=notice.receiver, topic=post.topic, user=current_user) if form.notice.data and not current_user.is_noticing(post.topic): current_user.notice(post.topic) if post.topic.author != current_user and post.topic.author.receive_post_notification: push_post_notification(post=post, receiver=post.topic.author) flash('帖子已发表', 'success') return redirect(url_for('main.show_post', post_id=post.id)) elif form.save.data: post.saved = True db.session.commit() flash('帖子已保存', 'success') return redirect(url_for('user.draft_post')) elif form.save1.data: post.saved = True db.session.commit() flash('请上传附件', 'info') return redirect(url_for('.upload_post', post_id=post.id)) form.title.data = post.title form.body.data = post.body return render_template('main/edit_post.html', form=form, post=post)