示例#1
0
def change_theme(theme_name):
    if theme_name not in current_app.config['FP_THEMES'].keys():
        abort(404)

    response = make_response(redirect_back())
    response.set_cookie('theme', theme_name, max_age=30 * 24 * 60 * 60)
    return response
示例#2
0
def delete_paper(paper_id):
    paper = Paper.query.filter_by(user=current_user).filter_by(
        id=paper_id).first_or_404()
    db.session.delete(paper)
    db.session.commit()
    flash('删除成功', 'success')
    return redirect_back()
示例#3
0
def delete_message(message_id):
    message = Message.query.filter_by(user=current_user).filter_by(
        id=message_id).first_or_404()
    db.session.delete(message)
    db.session.commit()
    flash('删除成功', 'success')
    return redirect_back()
示例#4
0
def new_paper():
    form = UrlForm()
    if form.validate_on_submit():
        url = form.url.data
        category_id = form.category.data
        create_and_notify.delay(url, category_id, current_user.id)
        flash('正在解析,请稍后在通知栏中查看结果', 'info')
        return redirect_back()
    return render_template('manage/new_paper.html', form=form)
示例#5
0
def new_category():
    form = NewCategoryForm()
    if form.validate_on_submit():
        category = Category(name=form.new_category_name.data,
                            user=current_user)
        db.session.add(category)
        db.session.commit()
        flash('创建成功', 'success')
        return redirect_back()
    return render_template('manage/new_category.html', form=form)
示例#6
0
def read_paper(paper_id):
    paper = Paper.query.filter_by(user=current_user).filter_by(
        id=paper_id).first_or_404()
    if paper.readed:
        paper.readed = False
        flash('成功从已读列表中删除', 'success')
    else:
        paper.readed = True
        flash('成功加入到已读列表', 'success')
    db.session.commit()
    return redirect_back()
示例#7
0
def star_paper(paper_id):
    paper = Paper.query.filter_by(user=current_user).filter_by(
        id=paper_id).first_or_404()
    if paper.stared:
        paper.stared = False
        flash('取消收藏成功', 'success')
    else:
        paper.stared = True
        flash('收藏成功', 'success')
    db.session.commit()
    return redirect_back()
示例#8
0
def add_comment(paper_id):
    paper = Paper.query.filter_by(user=current_user).filter_by(
        id=paper_id).first_or_404()
    form = CommentForm()
    if form.validate_on_submit():
        commented = form.commented.data
        paper.commented = commented
        db.session.commit()
        flash('评注成功', 'success')
        return redirect_back()
    form.commented.data = paper.commented
    return render_template('manage/edit_comment.html', form=form, paper=paper)
示例#9
0
def register():
    if current_user.is_authenticated:
        flash('请先登出用户', 'warning')
        return redirect_back()

    form = RegisterForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        new_user = User(username=username, password_hash=password)
        new_user.set_password(password)
        db.session.add(new_user)
        db.session.commit()
        initialize_user(new_user)
        flash('注册成功', 'info')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
示例#10
0
def edit_paper(paper_id):
    paper = Paper.query.filter_by(user=current_user).filter_by(
        id=paper_id).first_or_404()
    form = EditPaperForm()
    if form.validate_on_submit():
        paper.url = form.url.data
        paper.title = form.title.data
        paper.author = form.author.data
        paper.abstract = form.abstract.data
        paper.subjects = form.subjects.data
        paper.submit_time = form.submit_time.data
        paper.category = Category.query.get(form.category.data)
        db.session.commit()
        flash('修改成功', 'success')
        return redirect_back()
    form.url.data = paper.url
    form.title.data = paper.title
    form.author.data = paper.author
    form.abstract.data = paper.abstract
    form.subjects.data = paper.subjects
    form.submit_time.data = paper.submit_time
    form.category.data = paper.category.id
    return render_template('manage/edit_paper.html', form=form, paper=paper)