Esempio n. 1
0
def problem_list():
    page = int(request.args.get('p')) if 'p' in request.args else 1
    div = 20
    user_id = session['user']['id']

    problem_count = g.db.query('SELECT count(*) as count FROM problem',
                               isSingle=True)['count']
    problems = g.db.query(
        'SELECT p.id,p.name,p.category FROM problem as p limit ?,?',
        ((page - 1) * div, div))
    solved = g.db.query(
        'SELECT s.problem FROM solved as s WHERE owner=? AND status="CORRECT"',
        (user_id, ))

    problems_map = {}

    for problem in problems:
        problems_map[problem['id']] = problem

    for item in solved:
        problems_map[item['problem']]['solved'] = True

    pagination = Pagination(page, div, problem_count)
    return render_template('problems.html',
                           title='Problems',
                           pagination=pagination,
                           problems=problems)
Esempio n. 2
0
def problems():
    page = int(request.args.get('p')) if 'p' in request.args else 1
    div = 20

    problem_count = g.db.query('SELECT count(*) as count FROM problem', isSingle=True)['count']
    problems = g.db.query('SELECT p.id,p.name,p.status FROM problem as p group by p.name limit ?,?', ((page-1)*div, div))

    pagination = Pagination(page, div, problem_count)

    return render_template('admin/problems.html', now='problem', pagination=pagination, problems=problems)
Esempio n. 3
0
def list_challenge():
    page = int(request.args.get('p', 1))
    div = 20

    challenges = Challenge.list()
    pagination = Pagination(page, div, challenges.count())
    return render_template('challenges.html',
                           title='Challenges',
                           pagination=pagination,
                           challenges=challenges)
Esempio n. 4
0
def history_list():
    page = int(request.args.get('p', 1))
    div = 20
    histories = History.query.filter(
        History.owner_id == current_user.id).order_by(
            History.id.desc()).offset((page - 1) * div).limit(div)
    pagination = Pagination(page, div, histories.count())

    return render_template('history.html',
                           histories=histories,
                           pagination=pagination)
Esempio n. 5
0
def users():
    page = int(request.args.get('p')) if 'p' in request.args else 1
    div = 20

    user_count = g.db.query('SELECT count(*) as count FROM user', isSingle=True)['count']
    users = g.db.query('SELECT u.id, u.password, u.role FROM user as u group by u.id limit ?,?',
                       ((page - 1) * div, div))

    pagination = Pagination(page, div, user_count)

    return render_template('admin/users.html', now='user', pagination=pagination, users=users)
Esempio n. 6
0
def snippet_list():
    page = int(request.args.get('p')) if 'p' in request.args else 1
    div = 20

    owner = session['user']['id']

    snippet_count = g.db.query('SELECT count(*) as count FROM snippets WHERE owner=?', (owner,), isSingle=True)['count']
    snippets = g.db.query('SELECT * FROM snippets WHERE owner=? limit ?,?', (owner, (page - 1) * div, div))

    pagination = Pagination(page, div, snippet_count)
    return render_template('snippets.html', title='Snippets', pagination=pagination, snippets=snippets)
Esempio n. 7
0
def snippet_list():
    page = int(request.args.get('p', 1))
    div = 20

    q = Snippet.query.filter(Snippet.owner_id == current_user.id)
    snippets = q.offset((page - 1) * div).limit(div)

    pagination = Pagination(page, div, q.count())
    return render_template('snippets.html',
                           title='Snippets',
                           pagination=pagination,
                           snippets=snippets)
Esempio n. 8
0
def users():
    page = int(request.args.get('p', 1))
    div = 20

    user_count = User.query.count()
    users = User.query.offset((page - 1) * div).limit(div)

    pagination = Pagination(page, div, user_count)

    return render_template('admin/users.html',
                           now='user',
                           pagination=pagination,
                           users=users)
Esempio n. 9
0
def history_list():
    page = int(request.args.get('p') if 'p' in request.args else '1')
    div = 20
    user_id = session['user']['id']
    histories = g.db.query(
        'SELECT s.id, s.status, s.problem, (SELECT p.name FROM problem as p WHERE p.id = s.problem) AS probname FROM solved AS s WHERE owner=? ORDER BY time DESC LIMIT ?, ?',
        (user_id, (page - 1) * div, div))
    history_count = g.db.query(
        'SELECT COUNT(1) AS cnt FROM solved WHERE owner=?', (user_id, ),
        isSingle=True)['cnt']
    pagination = Pagination(page, div, history_count)

    return render_template('history.html',
                           histories=histories,
                           pagination=pagination)