Пример #1
0
def view_cart():
    if not users_manager.is_teacher():
        notifiers.permission_denied()
        return redirect(url_for('tasks_list'))
    db_response = json.loads(cart_manager.view_cart(request.cookies.get('problems_login')))
    if db_response['code'] != 0:
        notifiers.db_error()
        return redirect(url_for('tasks_list'))
    return render_template('cart.html', tasks_list=db_response['rows'])
Пример #2
0
def users_list():
    if not users_manager.is_admin():
        notifiers.permission_denied()
        return redirect(url_for('main_page'))
    db_response = json.loads(users_manager.users_list())
    if db_response['code'] != 0:
        notifiers.db_error()
        return redirect(url_for('main_page'))
    return render_template('users.html', users_list=db_response['rows'])
Пример #3
0
def change_role():
    if not users_manager.is_admin():
        notifiers.permission_denied()
        return redirect(url_for('main_page'))
    resp = json.loads(users_manager.change_role(request.form['login'], request.form['role']))
    if resp['code'] != 0:
        notifiers.db_error()
    else:
        notifiers.role_changed()
    return json.dumps(resp)
Пример #4
0
def add_to_cart(task_id):
    if not users_manager.is_teacher():
        notifiers.permission_denied()
        return redirect(url_for('tasks_list'))
    if cart_manager.add_to_cart(task_id, request.cookies.get('problems_login')):
        notifiers.added_to_cart()
        return 'ok'
    else:
        notifiers.failed_to_add_to_cart()
        return 'fail'
Пример #5
0
def remove_from_cart(task_id):
    if not users_manager.is_teacher():
        notifiers.permission_denied()
        return redirect(url_for('tasks_list'))
    if cart_manager.remove_from_cart(task_id, request.cookies.get('problems_login')):
        notifiers.removed_from_cart()
        return redirect(url_for('view_cart'))
    else:
        notifiers.failed_to_remove_from_cart()
        return redirect(url_for('tasks_list'))
Пример #6
0
def edit_task_form(task_id):
    if not users_manager.is_admin():
        notifiers.permission_denied()
        return redirect(url_for('tasks_list'))
    db_response = json.loads(tasks_manager.get_task(task_id))
    if len(db_response['rows']) == 0:
        notifiers.db_error()
        return redirect(url_for('tasks_list'))
    task = db_response['rows'][0]
    return render_template('edit_task.html', task=task)
Пример #7
0
def delete_task(task_id=None):
    if users_manager.is_admin():
        db_response = json.loads(tasks_manager.delete_task(task_id))
        if db_response['code'] == 0:
            notifiers.task_deleted()
        else:
            notifiers.db_error()
    else:
        notifiers.permission_denied()
    return redirect(url_for('tasks_list'))
Пример #8
0
def edit_task():
    if not users_manager.is_admin():
        notifiers.permission_denied()
        return redirect(url_for('login_form'))
    db_response = json.loads(
        tasks_manager.edit_task(request.form['task_id'], request.form['name'], request.form['topic'],
                                request.form['difficulty'],
                                request.form['statement'], request.form['solution'], request.form['answer']))
    print(str(db_response))
    if db_response['code'] != 0:
        notifiers.db_error()
    return redirect(url_for('tasks_list'))
Пример #9
0
def check_task():
    if users_manager.is_student():
        resp = json.loads(tasks_manager.check_task(request.form['task_id'], request.cookies.get('problems_login'),
                                                   request.form['answer']))

        if resp['code'] == 0:
            notifiers.task_accepted()
        elif resp['code'] == 1:
            notifiers.task_rejected()
        else:
            notifiers.db_error()
        return json.dumps(resp)
    else:
        notifiers.permission_denied()
        return redirect(url_for('tasks_list'))
Пример #10
0
def add_task():
    if users_manager.is_admin():
        return render_template('add_task.html')
    else:
        notifiers.permission_denied()
        return redirect(url_for('tasks_list'))