예제 #1
0
def study(set_id):
    set = get_set(set_id)
    if not set:
        return render_template('not_found.html')
    if set.public or (current_user.is_authenticated
                      and set.user == current_user.id):
        return render_template('set-study.html', set=set)
    else:
        flash("You are not authorized to view this set!", "error")
        return redirect(url_for('home.home'))
예제 #2
0
def info():
    set_id = request.args.get('set')
    set = get_set(set_id)
    num_cards = set.num_cards()
    num_sides = set.num_sides()
    sides = set.get_side_names()
    cards = set.get_card_info()
    return json.jsonify({
        'num_cards': num_cards,
        'num_sides': num_sides,
        'sides': sides,
        'cards': cards,
    })
예제 #3
0
def delete(set_id):
    set = get_set(set_id)
    if not set:
        return render_template('not_found.html')
    if current_user.is_authenticated and set.user == current_user.id:
        delete_set(set_id)
        flash("Set '" + set.name + "' was deleted!", "success")
        return redirect(url_for('home.home'))
    elif set.public:
        flash("You are not authorized to delete this set!", "error")
        return redirect(url_for('set.set', set_id=set_id))
    else:
        flash("You are not authorized to delete this set!", "error")
        return redirect(url_for('home.home'))
예제 #4
0
def edit(set_id):
    if request.method == 'POST':
        edit_form(request.form, set_id)
        return redirect(url_for('set.set', set_id=set_id))
    set = get_set(set_id)
    if not set:
        return render_template('not_found.html')
    if current_user.is_authenticated and set.user == current_user.id:
        return render_template('set-edit.html', set=set)
    elif set.public:
        flash("You are not authorized to edit this set!", "error")
        return redirect(url_for('set.set', set_id=set_id))
    else:
        flash("You are not authorized to view this set!", "error")
        return redirect(url_for('home.home'))
예제 #5
0
def set(set_id):
    set = get_set(set_id)
    if not set:
        return render_template('not_found.html')
    if current_user.is_authenticated and set.user == current_user.id:
        set_info = set.get_card_info()
        return render_template('set.html',
                               set=set,
                               set_info=set_info,
                               view_only=False,
                               user=current_user)
    elif set.public:
        user = User.query.filter_by(id=set.user).one()
        set_info = set.get_card_info()
        return render_template('set.html',
                               set=set,
                               set_info=set_info,
                               view_only=True,
                               user=user)
    else:
        flash("You are not authorized to view this set!", "error")
        return redirect(url_for('home.home'))
예제 #6
0
def done():
    set_id = request.args.get('set')
    set = get_set(set_id)
    num_cards = set.num_cards()
    return render_template('study-done.html', set_id=set_id, num_cards=num_cards)