Esempio n. 1
0
def reply_post(replied_id):
    replied = Post.query.get_or_404(replied_id)
    if replied.topic.group.status_id == 1 and not current_user.can('MEMBER'):
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        author = current_user._get_current_object()
        post = Post(body=body,
                    title=title,
                    author=author,
                    topic_id=replied.topic_id,
                    replied_id=replied_id)
        db.session.add(post)
        if form.publish.data:
            reads = Read.query.filter(Read.reader_id != current_user.id).all()
            if reads:
                for read in reads:
                    db.session.delete(read)
            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:
                current_user.notice(post.topic)
            if current_user != post.topic.author 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 = 'Re:' + replied.title
    return render_template('main/reply_post.html', form=form, replied=replied)
Esempio n. 2
0
def fake_posts(count=100):
    for i in range(count):
        post = Post(title=fake.sentence(),
                    body=fake.text(500),
                    author=User.query.get(random.randint(1, User.query.count())),
                    timestamp=fake.date_time_this_year(),
                    topic_id=random.randint(1, Topic.query.count()))
        db.session.add(post)
        #post.time = post.timestamp.strftime(format("%m%d%H%M%S"))
    db.session.commit()
Esempio n. 3
0
def new_post(topic_id):
    topic = Topic.query.get_or_404(topic_id)
    if topic.group.status_id == 1 and not current_user.can('MEMBER'):
        abort(403)
    if topic.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
        post = Post(title=title,
                    body=body,
                    topic=topic,
                    author=current_user._get_current_object())
        db.session.add(post)
        if form.publish.data:
            db.session.commit()
            if topic.receivers:
                for notice in topic.receivers:
                    send_new_post_email(receiver=notice.receiver,
                                        topic=topic,
                                        user=current_user)
            if form.notice.data:
                current_user.notice(topic)
            if current_user != topic.author and topic.author.receive_post_notification:
                push_post_notification(post=post, receiver=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 = 'Re:' + topic.name
    return render_template('main/new_post.html', form=form, topic=topic)