Exemplo 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)
Exemplo n.º 2
0
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)
Exemplo 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)