def delete_success(self): oid = subjectBLL.insert("Asignatura Muy Nueva", "AMN", 6, 3, "Obligatoria", 1) subject = subjectBLL.get_by_name("Asignatura Muy Nueva") if subject is None: raise BLLException("The subject was not created") subjectBLL.delete(oid) subject = subjectBLL.get_by_name("Asignatura Muy Nueva") if subject is not None: raise BLLException("The subject hasn't been deleted")
def update_success(self): subject_list = subjectBLL.get_all() old_subject = subject_list[0] oid = old_subject["subjectId"] subjectBLL.update(oid, "Asignatura Muy Nueva", "AMN", 12, 1, "Obligatoria", 1) subject = subjectBLL.get_by_name(old_subject["name"]) if subject is not None: raise BLLException( "The subject has the same name as before the change") subject = subjectBLL.get_by_name("Asignatura Muy Nueva") if subject is None: raise BLLException("The subject has not got the new name")
def check_RN005_date_hour_correct(self, dateAppointment, hourAppointment, tutorialId): dayWeek = calendar.day_name[dateAppointment.weekday()] tutorial = tutorial_bll.get_by_OID(tutorialId) if dayWeek != tutorial["dayWeek"] or hourAppointment < tutorial[ "startTime"] or hourAppointment >= tutorial["endTime"]: raise BLLException("Appointment no valid.")
def check_category(self, cat): lista = [ "Catedrático", "Titular de Universidad", "Profesor Contratado Doctor", "Profesor Ayudante Doctor" ] if cat not in lista: raise BLLException( f"Cannot add or update teacher with category = {cat}")
def delete(self, oid): self.check_teacherId_exists(oid) try: deleted_id = super().delete(oid) except DALException as exc: raise BLLException(exc) from exc return deleted_id
def delete(self, oid): # Check that the OID exists self.check_oid_exists(oid) try: res = super().delete(oid) except DALException as exc: raise BLLException(exc) from exc return res
def check_RN008_selectividad(self, accessMethod, birthDateSt): if accessMethod != "Selectividad": return date_now = datetime.now() date_birth_student = datetime.strptime(birthDateSt, "%Y-%m-%d") diff = date_now - date_birth_student if diff.days // 365 < 16: raise BLLException("The student is younger than 16 years old")
def insert(self, dayWeek, startTime, endTime, teacherId): self.check_attributes_not_empty(dayWeek, startTime, endTime) self.check_weekday(dayWeek) self.check_RN018_PAD(teacherId, startTime, endTime) try: tutorialId = super().insert(dayWeek, startTime, endTime, teacherId) except DALException as exc: raise BLLException(exc) from exc return tutorialId
def check_RN018_PAD(self, teacherId, startTime, endTime): teacher = teacher_bll.get_by_OID(teacherId) if teacher["category"] == "Profesor Ayudante Doctor": start = datetime.strptime(startTime, "%H:%M:%S") end = datetime.strptime(endTime, "%H:%M:%S") total = end - start if total.seconds // 3600 > 2: raise BLLException( "A PAD teacher cannot give more than 2 hours of tutorials a week." ) tutorials_by_teacher = self.get_by_teacherId(teacherId) if tutorials_by_teacher is not None: for t in tutorials_by_teacher: start = t["startTime"] end = t["endTime"] diff = end - start total = total + diff if total.seconds // 3600 > 2: raise BLLException( "A PAD teacher cannot give more than 2 hours of tutorials a week." )
def insert(self, dateAppointment, hourAppointment, tutorialId, studentId): self.check_attributes_not_empty(dateAppointment, hourAppointment, tutorialId, studentId) self.check_RN005_date_hour_correct(dateAppointment, hourAppointment, tutorialId) try: appointmentId = super().insert(dateAppointment, hourAppointment, tutorialId, studentId) except DALException as exc: raise BLLException(exc) from exc return appointmentId
def insert(self, name, acronym, n_credits, course, subject_type, degreeId): # Check that the name and acronym are not empty check_not_null(name, "The subject's name cannot be empty") check_not_null(acronym, "The subject's acronym cannot be empty") check_not_null(n_credits, "The subject's credits cannot be empty") # Insert the new subject try: oid = super().insert(name, acronym, n_credits, course, subject_type, degreeId) except DALException as exc: raise BLLException(exc) from exc return oid
def insert(self, dni, firstName, surname, birthDate, email, category): self.check_attributes_not_empty(dni, firstName, surname, birthDate, email, category) self.check_category(category) self.check_dni_unique(dni) self.check_email_unique(email) self.check_RN017_email(email) try: teacherId = super().insert(dni, firstName, surname, birthDate, email, category) except DALException as exc: raise BLLException(exc) from exc return teacherId
def update(self, oid, name, acronym, n_credits, course, subject_type, degreeId): # Check that the name and acronym are not empty, and that the OID exists self.check_oid_exists(oid) check_not_null(name, "The subject's name cannot be empty") check_not_null(acronym, "The subject's acronym cannot be empty") check_not_null(n_credits, "The subject's credits cannot be empty") try: new_oid = super().update(oid, name, acronym, n_credits, course, subject_type, degreeId) except DALException as exc: raise BLLException(exc) from exc return new_oid
def insert(self, accessMethod, dniSt, firstNameSt, surnameSt, birthDateSt, emailSt): self.check_attributes_not_empty(accessMethod, dniSt, firstNameSt, surnameSt, birthDateSt, emailSt) self.check_accessMethod(accessMethod) self.check_dni_unique(dniSt) self.check_email_unique(emailSt) self.check_RN017_email(emailSt) self.check_RN008_selectividad(accessMethod, birthDateSt) try: studentId = super().insert(accessMethod, dniSt, firstNameSt, surnameSt, birthDateSt, emailSt) except DALException as exc: raise BLLException(exc) from exc return studentId
def check_weekday(self, day): lista = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] if day not in lista: raise BLLException(f"Cannot add or update tutorial on {day}")
def check_teacherId_exists(self, oid): teacher = self.get_by_OID(oid) if teacher is None: raise BLLException(f"There exists no teacher with ID {oid}")
def check_email_unique(self, email): for student in self.get_all(): if email == student["emailSt"]: raise BLLException("Two people cannot have the same email")
def check_email_unique(self, email): for teacher in self.get_all(): if email == teacher["email"]: raise BLLException("Two people cannot have the same email")
def check_studentId_exists(self, oid): student = self.get_by_OID(oid) if student is None: raise BLLException(f"There exists no user with ID {oid}")
def check_tutorialId_exists(self, oid): tutorial = self.get_by_OID(oid) if tutorial is None: raise BLLException(f"There exists no tutorial with ID {oid}")
def check_appointmentId_exists(self, oid): appointment = self.get_by_OID(oid) if appointment is None: raise BLLException(f"There exists no appointment with ID {oid}")
def check_dni_unique(self, dni): for teacher in self.get_all(): if dni == teacher["dni"]: raise BLLException("Two people cannot have the same DNI")
def check_accessMethod(self, access): lista = ["Selectividad", "Ciclo", "Mayor", "Titulado Extranjero"] if access not in lista: raise BLLException( f"Cannot add or update student with accessMethod = {access}")
def check_RN017_email(self, email): is_valid = validate_email(email) if not is_valid: raise BLLException(f"The email {email} is not valid.")
def check_dni_unique(self, dni): for student in self.get_all(): if dni == student["dniSt"]: raise BLLException("Two people cannot have the same DNI")
def check_not_null(value, msg): if value is None or (isinstance(value, str) and value.strip() == ""): raise BLLException(msg)
def check_oid_exists(self, oid): # Check that there exists a subject with the provided OID subj = super().get_by_oid(oid) if subj is None: raise BLLException("Cannot find a subject with oid " + str(oid))