예제 #1
0
def save_user_subject(subject: MateriaClass.Materia, username: str):
    """This function saves a subject and associates to a user into the database

    Args:
        subject (MateriaClass.Materia): Subject that would be added to the database.
        username(str): User owner of the task.
    Returns:
        cur (Cursor): Database cursor that access to tasks and subjects.
    """
    materia_id = get_subject_id(subject.codigo)
    usuario_id = get_user_id(username)
    if not username:
        return
    if not check_user_subject_existence(materia_id, username):
        query = configuration.prepare_mysql_query(
            "INSERT INTO MateriasUsuarios (idMateria, idUsuario, MatID) values (?, ?, ?);"
        )
        conn = get_db()
        cur = conn.cursor()
        cur.execute(query, (materia_id, usuario_id, subject.id))
        conn.commit()
        conn.close()
    else:
        query = configuration.prepare_mysql_query(
            "UPDATE MateriasUsuarios SET MatID = ? WHERE idMateria = ? AND idUsuario = ?;"
        )
        conn = get_db()
        cur = conn.cursor()
        cur.execute(
            query,
            (subject.id, materia_id, usuario_id),
        )
        conn.commit()
        conn.close()
예제 #2
0
def save_task(task):
    """This function saves a task into the database

    Args:
        task (TareaClass.Tarea): Tasks that would be added to the database.
    """

    conn = get_db()
    cur = conn.cursor()
    query = configuration.prepare_mysql_query(
        "INSERT INTO Tareas(TarUID, TarTitulo, TarDescripcion, TarFechaLim, Materias_idMaterias) VALUES (?, ?, ?, ?, ?);"
    )
    if not check_task_existence(task):
        cur.execute(
            query,
            (
                task.id,
                task.title,
                task.description.replace("\\n", "\n"),
                task.due_date,
                task.subject_id,
            ),
        )
        conn.commit()
    conn.close()
예제 #3
0
def save_user(username: str):
    """This function saves a user into the database

    Args:
        username (str): User to be added into the database

    Returns:
        cur (Cursor): Database cursor that access to tasks and subjects.
    """
    query = configuration.prepare_mysql_query(
        "INSERT INTO Usuarios(UsrNombre) VALUES (?)")
    conn = get_db()
    cur = conn.cursor()
    cur.execute(query, (username, ))
    conn.commit()
    return cur
예제 #4
0
def update_subject(subject: MateriaClass.Materia):
    """This function saves a subject into the database

    Args:
        subject (MateriaClass.Materia): Subject that would be added to the database.

    Returns:
        cur (Cursor): Database cursor that access to tasks and subjects.
    """
    query = configuration.prepare_mysql_query(
        "UPDATE Materias SET MatNombre = ? WHERE MatCodigo = ?;")
    conn = get_db()
    cur = conn.cursor()
    cur.execute(query, (subject.name, subject.codigo))
    conn.commit()
    return cur
예제 #5
0
def save_subject_id(subject: MateriaClass.Materia):
    """DEPRECATED This function saves the trello list ID into the database

    Args:
        subject (MateriaClass.Materia): Subject that owns the ID that would be added to the database.

    """
    query = configuration.prepare_mysql_query(
        "UPDATE Materias SET MatID = ? WHERE MatCodigo = ?;")
    conn = get_db()
    cur = conn.cursor()
    cur.execute(
        query,
        (subject.id, subject.codigo),
    )
    conn.commit()
    conn.close()
예제 #6
0
def get_subject_from_id(subject_id) -> MateriaClass.Materia:
    """This function gets a subject object from the database

    Args:
        subject_code (str): Subject code for get the subject name.

    Returns:
        subject (MateriaClass.Materia): The subject name from the subject code.
    """
    query = configuration.prepare_mysql_query(
        "select MatNombre, MatCodigo from Materias where idMaterias = '" +
        str(subject_id) + "'")
    conn = get_db()
    cur = conn.cursor()
    cur.execute(query)
    subject = None

    for row in cur.fetchall():
        subject = MateriaClass.Materia(row[0], row[1], id=subject_id)
    conn.close()
    return subject
예제 #7
0
def save_user_calendar_url(calendar_url: str, username: str):
    """This function saves a calendar_url to a user

    Args:
        calendar_url (str): Calendar url to ics
        username(str): User owner of the calendar.
    """
    usuario_id = get_user_id(username)
    if not username:
        return
    else:
        query = configuration.prepare_mysql_query(
            "UPDATE Usuarios SET UsrUrl = ? WHERE idUsuarios = ?;")
        conn = get_db()
        cur = conn.cursor()
        cur.execute(
            query,
            (calendar_url, usuario_id),
        )
        conn.commit()
        conn.close()
예제 #8
0
def save_user_task(task, username: str):
    """This function saves a task from a user into the database

    Args:
        task (TareaClass.Tarea): Tasks that would be added to the database.
        username(str): User owner of the task.
    """
    save_task(task)
    conn = get_db()
    cur = conn.cursor()
    tarea_id = get_task_id(task.id)
    usuario_id = get_user_id(username)
    query = configuration.prepare_mysql_query(
        "INSERT INTO TareasUsuarios(TarUsrEstado, idTareas, idUsuarios) VALUES (?,?,?);"
    )
    if not check_user_task_existence(task, username):
        cur.execute(
            query,
            ("N", tarea_id, usuario_id),
        )
        conn.commit()
    conn.close()
예제 #9
0
def add_task_tid(task_uid: str, task_tid: str, username: str):
    """This function adds the task trello ID into the database

    Args:
        task_uid (str): Task UID from ICS file.
        task_tid (str): New Task Trello ID from trello.
        username (str): Username from the user that owns the task

    Returns:
        cur (Cursor): Database cursor that access to tasks and subjects.
    """
    query = configuration.prepare_mysql_query(
        "UPDATE TareasUsuarios SET TarUsrTID = ?, TarUsrEstado = ? WHERE idUsuarios = ? AND idTareas = ?;"
    )
    conn = get_db()
    cur = conn.cursor()
    task_id = get_task_id(task_uid)
    user_id = get_user_id(username)
    cur.execute(
        query,
        (task_tid, "E", user_id, task_id),
    )
    conn.commit()
    conn.close()