def generate_student_sheet(login):
    latex_template = "\documentclass{article} \n" \
                     "\\usepackage[T2A]{fontenc} \n" \
                     "\\usepackage[utf8]{inputenc} \n" \
                     "\\usepackage[russian]{babel} \n" \
                     "\\begin{document} \n" \
                     "\section*{Задачи} \n"

    query = "SELECT problems.tasks.statement FROM problems.cart " \
            "INNER JOIN problems.tasks ON problems.tasks.task_id = problems.cart.task_id " \
            "WHERE login=%s"
    params = [
        login,
    ]
    db_response = json.loads(db.select_query(query, params))
    if db_response['code'] == 0:
        tasks_list = [i[0] for i in db_response['rows']]
        tasks_list = '\subsection{}' + '\n \n \subsection{}'.join(tasks_list)
        latex_template += tasks_list
        latex_template += "\n \end{document}"
        filename = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for _ in range(FILENAME_LENGTH))
        fout = open('static/latex/' + filename + '.tex', 'w')
        print(latex_template, file=fout)
        fout.close()
        os.system('pdflatex -output-directory static/latex ' + filename +
                  '.tex')
        return filename
    else:
        return None
Beispiel #2
0
def postTodos():
    data = request.data
    data_dict = json.loads(data)
    new_todo = data_dict["name"]
    insert_query(new_todo)
    results = select_query()
    return make_response(results), 201
Beispiel #3
0
def get_user_todos(request: Request):
    user = security.get_user(request)
    if not user:
        raise HTTPException(status_code=403,
                            detail="Unable to find your username.")
    tasks = db.select_query(
        f"select * from tasks where username = '******'username']}'")
    return tasks
def view_cart(login):
    query = "SELECT problems.tasks.task_id, problems.tasks.name FROM problems.cart " \
            "INNER JOIN problems.tasks ON problems.cart.task_id = problems.tasks.task_id " \
            "WHERE problems.cart.login = %s"
    params = [
        login,
    ]
    return db.select_query(query, params)
def in_cart(task_id, login):
    query = "SELECT * FROM problems.cart WHERE login=%s AND task_id=%s"
    params = [login, task_id]
    db_response = json.loads(db.select_query(query, params))
    if db_response['code'] == 0 and len(db_response['rows']) == 0:
        return False
    else:
        return True
Beispiel #6
0
def get_tasks_list(topic=None):
    params = []
    if topic is None:
        query = "SELECT task_id, name, topic, difficulty FROM problems.tasks"
    else:
        query = "SELECT task_id, name, topic, difficulty FROM problems.tasks " \
                "WHERE topic = %s"
        params.append(topic)
    return db.select_query(query, params)
def user_exists(login):
    query = "SELECT * FROM problems.users WHERE login = %s"
    params = [
        login,
    ]
    res = json.loads(db.select_query(query, params))
    if len(res["rows"]) > 0:
        return True
    else:
        return False
def check_credentials(login, password):
    query = "SELECT password, role FROM problems.users WHERE login=%s"
    params = [
        login,
    ]
    res = json.loads(db.select_query(query, params))
    if len(res["rows"]) == 0:
        resp = {"code": 1, "message": "Неверный логин", "role": -1}
    else:
        if password == res["rows"][0][0]:
            resp = {
                "code": 0,
                "message": "Успешная авторизация",
                "role": res["rows"][0][1]
            }
        else:
            resp = {"code": 2, "message": "Неверный пароль", "role": -1}
    return json.dumps(resp)
Beispiel #9
0
def check_task(task_id, login, answer):
    query = "SELECT answer FROM problems.tasks WHERE task_id=%s"
    params = [task_id,]
    db_response = json.loads(db.select_query(query, params))
    if db_response['code'] != 0:
        return json.dumps({'code': 2})
    reference = db_response['rows'][0][0]
    if answer == reference:
        if user_has_task(task_id, login):
            return json.dumps({'code': 3})
        else:
            query = "INSERT INTO problems.users_tasks(login, task_id) VALUES (%s, %s)"
            params = [login, task_id]
            db_response = json.loads(db.update_query(query, params))
            if db_response['code'] == 0:
                return json.dumps({'code': 0})
            else:
                return json.dumps({'code': 2})
    else:
        return json.dumps({'code': 1})
Beispiel #10
0
def user_has_task(task_id, login):
    query = "SELECT task_id, login FROM problems.users_tasks WHERE task_id=%s and login = %s"
    params = [task_id, login]
    db_response = json.loads(db.select_query(query, params))
    return len(db_response['rows']) > 0
Beispiel #11
0
def get_task(task_id):
    query = "SELECT task_id, name, topic, difficulty, statement, solution, answer FROM problems.tasks WHERE task_id=%s"
    params = [task_id,]
    return db.select_query(query, params)
def get_overall_rating():
    query = "SELECT problems.users.login, COUNT(task_id) FROM problems.users " \
            "INNER JOIN problems.users_tasks ON problems.users.login = problems.users_tasks.login " \
            "GROUP BY problems.users.login"
    db_response = json.loads(db.select_query(query, ()))
    return json.dumps(db_response)
Beispiel #13
0
def deleteTodos(todo_id):
    delete_query(todo_id)
    results = select_query()
    return make_response(results), 201
Beispiel #14
0
def getTodos():
    results = select_query()
    return make_response(results), 200
Beispiel #15
0
def updateTodos(todo_id):
    (_id, name, completed) = select_one_query(todo_id)
    update_query(todo_id, not completed)
    results = select_query()
    return make_response(results), 201
Beispiel #16
0
def get_topics_list():
    query = "SELECT topic_id, name FROM problems.topics"
    return db.select_query(query, ())
def users_list():
    query = "SELECT login, name, surname, role FROM problems.users"
    db_response = json.loads(db.select_query(query, ()))
    return json.dumps(db_response)