def GetStudentLeaves(self, roll_no: int = None, student_id: int = None, class_id: int = None, admission_id: int = None): # Initiate Transaction manager transaction_manager = TransactionalManager() try: db_conn = transaction_manager.GetDatabaseConnection("READ") leave_dao = LeaveDao(db_conn) student_leaves = None if admission_id: student_leaves = leave_dao.GetLeavesByAdmissionNo(admission_id) elif roll_no: if class_id: student_leaves = leave_dao.GetLeavesByStudentClassId( roll_no, class_id) else: raise Exception( 'Class id is required with student roll no.') elif student_id: student_leaves = leave_dao.GetStudentLeavesById(student_id) transaction_manager.end() return student_leaves # Add specific exceptions. except Exception: # Log exception. print("Exception occurred while fetching leaves for a user.") transaction_manager.end() raise
def upload_assignment(self, user_id, title, description, deadline, subject, class_, section, list_of_files, manual_marks): """ :return: """ return_val = None transaction_mgr = TransactionalManager() db_conn = transaction_mgr.GetDatabaseConnection("READWRITE") section = re.findall('\w+', section) return_msg = "" # comma separate all files comma_files = str() for file_count in range(0, len(list_of_files)): comma_files = comma_files + list_of_files[file_count] if file_count <= len(list_of_files) - 2: comma_files += ", " assignment_dao = AssignmentDao(db_conn, class_=class_, section=section, subject=subject, \ comma_files=comma_files, title=title, description=description, \ deadline=deadline, user_id=user_id) for file in list_of_files: # Fetching assignment type, type = re.search('__[\w]+?__', file) type = file[type.start(0) + 2:type.end(0) - 2] file_ext = file.split('.')[1] # Fetching file number for manual marks, file_num = re.search('_file\d{1}?_', file) file_num = file[file_num.start(0) + 1:file_num.end(0) - 1] if type == "manual": mark = manual_marks.get(file_num, "") return_val = assignment_dao.upload_manual( file, comma_files, mark, type) elif type == "subjective" and file_ext.startswith("xls"): return_val = assignment_dao.upload_subjective( file, comma_files, type) elif type == "mcq" and file_ext.startswith("xls"): return_val = assignment_dao.upload_MCQ(file, comma_files, type) # Break if any one fails if return_val[1] == True: return_msg += " " + return_val[0] else: break if return_val[1] == True: transaction_mgr.save() return return_msg transaction_mgr.end() return return_msg
def active_assignments(self, user_id): """ :param user_id: :return: """ return_val = None transaction_manager = TransactionalManager() db_conn = transaction_manager.GetDatabaseConnection("READWRITE") assignment_view = AssignmentDao(db_conn) return_val = assignment_view.active_assignment_by_userid(user_id) if return_val[1] == True: transaction_manager.save() return return_val[0] transaction_manager.end() return return_val[0]
def assignment_student_detail_view(self, assignment_id, teacher_id): """ :param assignment_id: :return: """ return_val = None transaction_manager = TransactionalManager() db_conn = transaction_manager.GetDatabaseConnection("READ") assignment_view = AssignmentView(db_conn) return_val = assignment_view.student_submissions_view_by_assignment( assignment_id, teacher_id) if return_val[1] == True: transaction_manager.save() return return_val[0] transaction_manager.end() return return_val[0]
def teacher_assignment_view(self, user_id, teacher_id, class_, section, subject): """ :return: """ return_val = None transaction_manager = TransactionalManager() db_conn = transaction_manager.GetDatabaseConnection("READWRITE") assignment_view = AssignmentView(db_conn) return_val = assignment_view.assignment_by_class_subject_id( user_id, teacher_id, class_, section, subject) if return_val[1] == True: transaction_manager.save() return return_val[0] transaction_manager.end() return return_val[0]
def delete_assignment(self, user_id, assignment_id): """ :param employee_id: :param assignment_id: :return: """ transaction_mgr = TransactionalManager() db_conn = transaction_mgr.GetDatabaseConnection("READWRITE") assignment_dao = AssignmentDao(db_conn) return_val = assignment_dao.delete_assignment_dao( user_id, assignment_id) if return_val[1]: transaction_mgr.save() return return_val transaction_mgr.end() return return_val
def UpdateStudentLeavesByParent(self, student_id: int = None, leave_date: str = None, remarks: str = None): transaction_manager = TransactionalManager() try: db_conn = transaction_manager.GetDatabaseConnection("READWRITE") leave_dao = LeaveDao(db_conn) status = None if student_id and leave_date and remarks: status = leave_dao.UpdateStudentLeaves(student_id, leave_date, remarks) transaction_manager.save() return status # Add specific exceptions. except Exception: # Log exception. print("Exception occurred while fetching leaves for a user.") transaction_manager.end() raise
def check_user(self, employee_id="", teacher_id=""): """ :return: """ return_val = None return_msg = None transaction_mgr = TransactionalManager() db_conn = transaction_mgr.GetDatabaseConnection("READ") if employee_id != "": check = CheckUser(db_conn) return_val = check.check_employee(employee_id) return_msg = return_val[0] elif teacher_id != "": check = CheckUser(db_conn) return_val = check.check_teacher(teacher_id) return_msg = return_val[0] transaction_mgr.end() return (return_msg, True) if return_val[1] else (return_msg, False)