def fake_topics(count=30): for i in range(count): topic = Topic(name=fake.sentence(), body=fake.text(500), group_id=random.randint(1, Forum.query.count()), author_id=random.randint(1, User.query.count()), timestamp=fake.date_time_this_year()) db.session.add(topic) #topic.time = topic.timestamp.strftime(format("%m%d%H%M%S")) db.session.commit()
def new_topic(group_id): if group_id == 6: abort(403) group = Group.query.get_or_404(group_id) if group.status_id == 1 and not current_user.can('MEMBER'): abort(403) if group.status_id == 2 and not current_user.can('MEMBER'): abort(403) form = PostForm() if form.validate_on_submit(): title = form.title.data body = form.body.data topic = Topic(name=title, body=body, group_id=group_id, author=current_user._get_current_object()) db.session.add(topic) if form.publish.data: current_user.read(topic) # 标记自己发表的文章为已读 db.session.commit() if form.notice.data: current_user.notice(topic) flash('主题已发表', 'success') return redirect(url_for('main.show_topic', topic_id=topic.id)) elif form.save.data: topic.saved = True db.session.commit() flash('主题已保存', 'success') return redirect(url_for('user.draft_topic')) elif form.save1.data: topic.saved = True db.session.commit() flash('请上传附件', 'info') return redirect(url_for('.upload_topic', topic_id=topic.id)) return render_template('main/new_topic.html', form=form, group=group)