示例#1
0
def edit_article(post_id):
    p = Post.query.get_or_404(post_id)
    if current_user != p.author and not (current_user.is_administrator() or current_user.is_moderator()):
        abort(403)
    edit_article_form = EditArticleForm(prefix='edit_article')
    if edit_article_form.validate_on_submit():
        p.title = edit_article_form.title.data.strip()
        p.body_html = edit_article_form.body_html.data.strip()
        if p.my_author is not p.my_album.my_creator:
            p.confirmed = False
        return redirect(url_for('main.post', post_id=p.id))

    return render_template('auth/articles/edit-article.html', post=p, editArticleForm=edit_article_form)
示例#2
0
def write_article(album_id):
    a = Album.query.get_or_404(album_id)
    if current_user != a.creator and not (current_user.is_administrator() or current_user.is_moderator()):
        abort(403)
    article_form = ArticleForm(prefix='article')
    if article_form.validate_on_submit():
        if current_user._get_current_object() is a.creator:
            p = Post(title=article_form.title.data.strip(), body_html=article_form.body_html.data.strip(), album=a,
                     author=current_user._get_current_object(), confirmed=True)
        else:
            p = Post(title=article_form.title.data.strip(), body_html=article_form.body_html.data.strip(), album=a,
                     author=current_user._get_current_object())
        db.session.add(p)
        current_user.send_message(user=a.creator, title=u'新文章需经过您的审核',
                                  content=u'<p>《%s》已由%s提交与专辑《%s》发表,</p>' % (p.title, current_user, a.title))
        return redirect(url_for('main.album', album_id=a.id))

    return render_template('auth/articles/write-article.html', articleForm=article_form)
示例#3
0
def edit_album(album_id):
    a = Album.query.get_or_404(album_id)
    if current_user != a.creator and not (current_user.is_administrator() or current_user.is_moderator()):
        abort(403)
    edit_album_form = EditAlbumForm(obj=a, prefix='edit_album')
    if edit_album_form.validate_on_submit():
        app = current_app._get_current_object()
        if edit_album_form.picture.data.filename is not u'':
            if a.picture_url and \
                    os.path.isfile(os.path.join(app.config['UPLOAD_FOLDER'], 'album', a.picture_url)):
                os.remove(os.path.join(app.config['UPLOAD_FOLDER'], 'album', a.picture_url))
            a.picture_url = upload(f=edit_album_form.picture.data, folder='album')
        a.title = edit_album_form.title.data.strip()
        a.percentage = float(edit_album_form.percentage.data)
        a.introduction = edit_album_form.introduction.data.strip()
        a.confirmed = False
        return redirect(url_for('auth.my_albums'))

    return render_template('auth/albums/edit-album.html', album=a, editAlbumForm=edit_album_form)
示例#4
0
def album_manage(album_id):
    a = Album.query.get_or_404(album_id)
    if current_user != a.creator and not (current_user.is_administrator() or current_user.is_moderator()):
        abort(403)
    adopt_album_form = AdoptAlbumForm(prefix='adopt_album')
    if adopt_album_form.validate_on_submit():
        a.confirmed = True
        current_user.send_message(user=a.creator, title=u'《%s》审核成功,已公开发表' % a.title,
                                  content=u'<p>尊敬的<strong>%s</strong></p><p><a href="%s">《%s》</a>经 %s 审核成功,已公开发表。</p>'
                                          % (a.creator.username, url_for('main.album', album_id=a.id), a.title, current_user.username))
        return redirect(request.args.get('next') or url_for('auth.albums'))

    reject_album_form = RejectAlbumForm(prefix='reject_album')
    if reject_album_form.validate_on_submit():
        a.confirmed = False
        current_user.send_message(user=a.creator, title=reject_album_form.title.data.strip(),
                                  content=u'<p>尊敬的<strong>%s</strong></p><p>很遗憾,您的<a href="%s">《%s》</a>经 %s 审核后,发表请求被驳回,原因如下:</p><p>%s</p>'
                                          % (a.creator.username, url_for('main.album', album_id=a.id), a.title, current_user.username, reject_album_form.content.data.strip()))
        return redirect(request.args.get('next') or url_for('auth.albums'))

    return render_template('auth/albums/album-manage.html', album=a, adoptAlbumForm=adopt_album_form,
                           rejectAlbumForm=reject_album_form)
示例#5
0
def post_manage(post_id):
    p = Post.query.get_or_404(post_id)
    if current_user != p.author and not (current_user.is_administrator() or current_user.is_moderator()):
        abort(403)
    adopt_post_form = AdoptPostForm(prefix='adopt_post')
    if adopt_post_form.validate_on_submit():
        p.confirmed = True
        current_user.send_message(user=p.author, title=u'《%s》审核成功,已公开发表' % p.title,
                                  content=u'<p>尊敬的<strong>%s</strong></p><p><a href="%s">《%s》</a>经 %s 审核成功,已公开发表。</p>'
                                          % (p.author.username, url_for('main.post', post_id=p.id), p.title, current_user.username))
        return redirect(request.args.get('next') or url_for('auth.manage_articles', album_id=p.album.id))

    reject_post_form = RejectPostForm(prefix='reject_post')
    if reject_post_form.validate_on_submit():
        p.confirmed = False
        current_user.send_message(user=p.author, title=reject_post_form.title.data.strip(),
                                  content=u'<p>尊敬的<strong>%s</strong></p><p>很遗憾,您的<a href="%s">《%s》</a>经 %s 审核后,发表请求被驳回,原因如下:</p><p>%s</p>'
                                          % (p.author.username, url_for('main.post', post_id=p.id), p.title, current_user.username, reject_post_form.content.data.strip()))
        return redirect(request.args.get('next') or url_for('auth.manage_articles', album_id=p.album.id))

    return render_template('auth/articles/post-manage.html', post=p, adoptPostForm=adopt_post_form,
                           rejectPostForm=reject_post_form)
示例#6
0
文件: views.py 项目: Smashman/mods.tf
def token(user_id=None):
    user = None
    token_form = None
    if not current_user.is_moderator():
        return abort(403)
    if user_id:
        user = User.query.get_or_404(user_id)
        token_form = TokenGrant()

        if token_form.validate_on_submit():
            user.user_class = 1 if token_form.is_moderator.data else 0
            user.upload_credits = token_form.token_number.data
            db.session.add(user)
            db.session.commit()
            flash("Save successful.", "success")
            return redirect(url_for("users.user_page",
                                    user_id=user.account_id))

        token_form.is_moderator.data = user.is_moderator()
        token_form.token_number.data = user.upload_credits
    return render_template('moderator/token.html',
                           title="Grant tokens",
                           user=user,
                           token_form=token_form)
示例#7
0
def manage_articles(album_id):
    a = Album.query.get_or_404(album_id)
    if current_user != a.creator and not (current_user.is_administrator() or current_user.is_moderator()):
        abort(403)

    return render_template('auth/articles/album-articles-manage.html', album=a)