def consultar(id):
    with closing(con()) as connection, closing(connection.cursor()) as cursor:
        cursor.execute(f"SELECT * FROM {model_name} WHERE id = ?", (int(id), ))
        row = cursor.fetchone()
        if row == None:
            return None
        return Professor.criar({"id": row[0], "nome": row[1]})
def consultar_por_nome(nome):
    with closing(con()) as connection, closing(connection.cursor()) as cursor:
        cursor.execute(f"SELECT id, nome, rg FROM {model_name} WHERE nome = ?", (nome,))
        row = cursor.fetchone()
        if row == None:
            return None
        return Professor.criar_com_id(row[0],row[1],row[2])
def criar(id, nome):
    if localizar(id) != None:
        raise ProfessorJaExiste()
    log = Log(None)
    criado = Professor(id, nome)
    professores_db.append(criado)
    log.finalizar(criado)
    return criado
def listar():
    with closing(con()) as connection, closing(connection.cursor()) as cursor:
        cursor.execute(f"SELECT * FROM {model_name}")
        rows = cursor.fetchall()
        registros = []
        for (id, nome) in rows:
            registros.append(Professor.criar({"id": id, "nome": nome}))
        return registros
Beispiel #5
0
def cria(id, nome):
    if localizar(id) != None:
        raise ProfessorJaExiste()
    log = Log(None)
    criado = Professor(id, nome)
    criar_dao(criado)
    log.finalizar(criado)
    return listar()
Beispiel #6
0
def listar():
    with closing(con()) as connection, closing(connection.cursor()) as cursor:
        cursor.execute(f"SELECT id, nome, rg FROM {model_name}")
        rows = cursor.fetchall()
        registros = []
        for (id, nome, rg) in rows:
            professor = Professor.criar_com_id(id, nome, rg)
            if professor != None:
                registros.append(professor)
        return registros
Beispiel #7
0
def remover(id):
    dados_professor = localizar(id)
    if dados_professor == None:
        return 0
    dao_remover(Professor.criar(dados_professor))
    return 1

    if localizar(id) == None:
        return 0
    dao_remover(id)
    return 1
def atualizar(professor_data):
    if localizar_por_nome(professor_data['nome']) != None:
        professor = Professor.criar(professor_data)
        dao_alterar(professor)
        return localizar(professor.id)
    return None
def criar(professor_data):
    if localizar_por_nome(professor_data['nome']) == None:
        professor = Professor.criar(professor_data)
        return dao_cadastrar(professor).__dict__()
    return None
Beispiel #10
0
def localizar(id):
    cursor.execute(sql_localizar, (id, ))
    linha = cursor.fetchone()
    if linha == None:
        return None
    return Professor(linha[0], linha[1])
Beispiel #11
0
def listar():
    cursor.execute(sql_listar)
    resultado = []
    for id, nome in cursor.fetchall():
        resultado.append(Professor(id, nome))
    return resultado
Beispiel #12
0
def atualizar(id, nome):
    professor = Professor.criar({"id": id, "nome": nome})
    dao_alterar(professor)
    return localizar(id)
Beispiel #13
0
def criar(professor_data):
    if localizar(professor_data['id']) == None:
        professor = Professor.criar(professor_data)
        return dao_cadastrar(professor)
    return None
Beispiel #14
0
    def __init__(self):
        self.students = {}

        #add to student dictionary
        s = Student(1, "Carson", "Alexander", "09012005")
        self.students[s.student_id] = s
        s = Student(2, "Meredith", "Alonso", "09022002")
        self.students[s.student_id] = s
        s = Student(3, "Arturo", "Anand", "09032003")
        self.students[s.student_id] = s
        s = Student(4, "Gytis", "Barzdukas", "09012001")
        self.students[s.student_id] = s
        s = Student(5, "Peggy", "Justice", "09012001")
        self.students[s.student_id] = s
        s = Student(6, "Laura", "Norman", "09012003")
        self.students[s.student_id] = s
        s = Student(7, "Nino", "Olivetto", "09012005")
        self.students[s.student_id] = s

        self.professors = {}

        #professor_id   first_name   last_name  hire_date
        p = Professor(1, "Kim", "Abercrombie", "1995-03-11")
        self.professors[p.professor_id] = p

        p = Professor(2, "Fadi", "Fakhouri", "2002-07-06")
        self.professors[p.professor_id] = p

        p = Professor(3, "Roger", "Harui", "1998-07-01")
        self.professors[p.professor_id] = p

        p = Professor(4, "Candace", "Kapoor", "2001-01-15")
        self.professors[p.professor_id] = p

        p = Professor(5, "Roger", "Zheng", "2004-02-12")
        self.professors[p.professor_id] = p

        self.courses = {}

        #add to course dictionary
        c = Course(1050, "Chemistry", 3, self.professors[1])
        self.courses[c.course_id] = c
        c = Course(4022, "Microeconomics", 3, self.professors[3])
        self.courses[c.course_id] = c
        c = Course(4041, "Macroeconomics", 3, self.professors[3])
        self.courses[c.course_id] = c
        c = Course(1045, "Calculus", 4, self.professors[4])
        self.courses[c.course_id] = c
        c = Course(3141, "Trigonometry", 4, self.professors[4])
        self.courses[c.course_id] = c
        c = Course(2021, "Composition", 3, self.professors[2])
        self.courses[c.course_id] = c
        c = Course(2042, "Literature", 4, self.professors[5])
        self.courses[c.course_id] = c

        self.enrollments = {}

        #add enrolled students into courses
        enroll_id = 11050  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[1],
                                self.courses[1050])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 14022  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[1],
                                self.courses[4022])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 14041  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[1],
                                self.courses[4041])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 21045  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[2],
                                self.courses[1045])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 23141  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[2],
                                self.courses[3141])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 22021  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[2],
                                self.courses[4041])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 31050  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[3],
                                self.courses[1050])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 41050  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[4],
                                self.courses[1050])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 44022  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[4],
                                self.courses[4022])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 54041  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[5],
                                self.courses[2021])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 61045  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[6],
                                self.courses[1045])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 73141  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[7],
                                self.courses[3141])
        self.enrollments[enroll_id] = enrollment