def start(self): """ Starts the menu of the manager :return: """ should_exit = False while not should_exit: os.system('clear') ManagerView.display_manager_menu(self.manager.login, 'Manager') user_input = ManagerView.get_option_input() if user_input == '1': self.promote_user_to_mentor() elif user_input == '2': self.remove_mentor() elif user_input == '3': self.edit_mentor_data() elif user_input == '4': self.display_mentors() elif user_input == '5': self.display_students() elif user_input == '6': self.display_all_canvas_members() elif user_input == '7': self.change_user_role() elif user_input == '8': self.send_email_to_all() elif user_input == '0': should_exit = True UserContainer.get_instance().save_users_to_file() os.system('clear')
def start(self): """ Main method of StudentController :return: None """ should_exit = False self.update_user_assignments() while not should_exit: try: os.system('clear') StudentView.display_student_menu(self.student.login, 'Student') user_input = StudentView.get_user_input('Choose an option: ') if user_input == '1': self.submit_assignment() StudentView.display_submission_result() elif user_input == '2': self.show_student_grades() elif user_input == '3': should_exit = True except IndexError: StudentView.print_wrong_assignment_id_error() except ValueError: StudentView.print_wrong_assignment_id_error() except Exception: tb = traceback.format_exc() print(tb) input() UserContainer.get_instance().save_users_to_file() os.system('clear')
def start(self): """ Main loop for the program """ exit_program = True RootView.display_animate_starting_screen() p = subprocess.Popen(['java', '-jar', 'dependencies/music.jar']) while exit_program: try: os.system('clear') RootView.display_main_menu_screen() RootView.display_main_menu() option = getch() if option == '1': self.handle_sign_in() elif option == '2': self.handle_sign_up() elif option == '3': RecoveryController().start() elif option == '0': UserContainer.get_instance().save_users_to_file() p.terminate() exit_program = False except RuntimeError: sys.stdout.flush()
def change_password(self, password: str, token: str): """ Method changes password. :param password: str -> user's new password :param token: str -> token needed to auth :return: None """ self.raise_exception_if_user_token_is_not_correct(token) self.user.password = PasswordService.encrypt_password(password) delattr(self.user, 'token') UserContainer.get_instance().save_users_to_file()
def __set_token(self): """ Method sets token to new generated one if player starts new recovery password process :return: None """ if 'token' in self.user.__dict__: self.generated_token = self.user.token else: self.generated_token = self.generate_new_token() self.user.token = self.generated_token self.send_token_to_user() UserContainer.get_instance().save_users_to_file()
def __init__(self, user_login_or_email: str, token: str = None): self.user = UserContainer.get_instance().get_user_by_login_or_email( user_login_or_email) self.__raise_exception_if_user_login_or_email_is_incorrect() self.__set_token() if token: self.raise_exception_if_user_token_is_not_correct()
def start(self): """ Starts controller :return: None """ exit_program = False while not exit_program: try: option = MentorView.display_menu() if option == '1': self.show_students() elif option == '2': self.add_assignment() elif option == '3': self.show_assignments() elif option == '4': self.grade_assignment() elif option == '5': self.check_attendance() elif option == '6': self.change_student_data() elif option == '7': self.promote_user_to_student() elif option == '8': self.edit_groups() elif option == '9': self.edit_groups(False) elif option == '0': exit_program = True else: MentorView.show_invalid_input() except IndexError: MentorView.display_index_error() except ValueError as error: if 'invalid literal' in str(error): MentorView.show_invalid_input() else: MentorView.display_date_error() except AttributeError: MentorView.display_group_exists() except Exception: tb = traceback.format_exc() print(tb) input() UserContainer.get_instance().save_users_to_file()
def grade_assignment(self): """ Adds grade to chosen assigment :return: None """ students_list = UserContainer.get_instance().get_students_list() if not students_list: MentorView.display_not_enough_data() return student_index = MentorView.get_student_index(students_list) student_index = int(student_index) student = students_list[student_index] assignment_index, grade = MentorView.get_grade_values(student) students_list = UserContainer.get_instance().get_students_list() students_list[student_index].assignments[ assignment_index].grade = grade
def show_students(self): """ Displays students data :return: None """ students_list = UserContainer.get_instance().get_students_list() MentorView.display_students_list(students_list)
def get_student_list(self): """ Method returns list of student instances that belongs to this group :return: list -> list of student instances """ student_instances = [] for login in self.student_login_list: student = UserContainer.get_instance().get_user_by_login_or_email(login) student_instances.append(student) return student_instances
def promote_user_to_student(self): """ Assignes user to students list :return: None """ not_assigned_users = UserContainer.get_instance( ).get_not_assigned_users_list() user_index = MentorView.get_user_index(not_assigned_users) user_index = int(user_index) user_to_assign = not_assigned_users[user_index] name = user_to_assign.name login = user_to_assign.login password = user_to_assign.password phone_number = user_to_assign.phone_number email = user_to_assign.email UserContainer.get_instance().remove_user(user_to_assign) if not user_to_assign: return user_to_assign = Student(name, login, password, phone_number, email) UserContainer.get_instance().add_user(user_to_assign)
def add_assignment(self): """ Adds new assigments :return: None """ students_list = UserContainer.get_instance().get_students_list() deadline, title, description = MentorView.return_assignment_values() new_assignment = Assignment(deadline, title, description) AssignmentContainer.get_instance().add_assignment(new_assignment) for student in students_list: student.add_student_assignment(deadline, title, description)
def change_student_data(self): """ Edits student data :return: None """ value_changing = True students_list = UserContainer.get_instance().get_students_list() if not students_list: MentorView.display_not_enough_data() return student_index = MentorView.get_student_index(students_list) student_index = int(student_index) student = students_list[student_index] while value_changing: value_to_change = MentorView.get_student_value_to_change() if value_to_change == '1': student.login = MentorView.get_new_value('login') elif value_to_change == '2': student.name = MentorView.get_new_value('name') elif value_to_change == '3': student.password = MentorView.get_new_value('password') elif value_to_change == '4': additional_days = MentorView.get_additional_attendance() student.attendance += int(additional_days) MentorView.show_invalid_input() elif value_to_change == '5': groups = GroupContainer.get_instance().get_groups_list() if not groups: MentorView.display_not_enough_data() return group_index = MentorView.get_group_index(groups) group_index = int(group_index) GroupContainer.get_instance().add_student_to_group( groups[group_index].name, student) UserContainer.get_instance().save_users_to_file() elif value_to_change == '6': return else: MentorView.show_invalid_input()
def submit_assignment(self): """ Add new key to submissions with assignment_name """ assignment_without_submission = [ assignment for assignment in self.student.assignments if assignment.submission is None ] if not assignment_without_submission: StudentView.print_user_assignments_list_empty_error() return assignments_as_strings_list = [ str(assignment) for assignment in assignment_without_submission ] StudentView.display_user_assignments(assignments_as_strings_list) submission_id = int(StudentView.get_user_input('Type submission ID: ')) submission_content = StudentView.get_user_input( 'Type link to github repository: ') self.student.add_submission( assignment_without_submission[submission_id].title, submission_content) UserContainer.get_instance().save_users_to_file()
def check_attendance(self): """ Checks if students from certain group are present and adds attendance count to group :return: None """ groups = GroupContainer.get_instance().get_groups_list() if groups: group_index = MentorView.get_group_index(groups) group_index = int(group_index) group = groups[group_index] else: MentorView.display_not_enough_data() return group_students = GroupContainer.get_instance().get_group( group.name).get_student_list() for student in group_students: student_present = MentorView.get_presence(student) if student_present: student.attendance += 1 UserContainer.get_instance().save_users_to_file() group.attendance_check_count += 1 GroupContainer.get_instance().save_groups_to_file()
def __init__(self): self.user_container = UserContainer.get_instance()
def __init__(self, student: Student): self.user_container = UserContainer.get_instance() self.student = student
def __init__(self, employee): self.user_container = UserContainer.get_instance() self.employee = employee
def __init__(self, manager: Manager): self.user_container = UserContainer.get_instance() self.manager = manager