def start_controller(students): """ Contain main logic for AttendanceController. Call functions that allow mentor check attendance and see student's prevous attendance. Args: student (:obj: `Student`): object representation of student """ students_attendance = AttendanceModel.get_attendance_list() user_choice = None menu_options = ["Check attendnace", "View student attendance"] while user_choice != "0": codecooler_view.clear_window() codecooler_view.print_menu("Student's attendance menu", menu_options, "Exit") user_choice = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] if user_choice == "1": _check_attendance(students_attendance, students) elif user_choice == "2": display_student_list(students) choosen_student = codecooler_view.get_inputs( "Student attendance detail", ["Student idx"]) attendance_student_list = _get_attendnace_list( students_attendance, choosen_student[0]) _calculate_attendnace(students_attendance, choosen_student[0]) codecooler_view.clear_window()
def get_students_grades(): """ Call functions to display detail about choosen student grades """ check_grades = codecooler_view.get_inputs("Do you want to see grades of any student?", ["Type \'Yes\' or anything else to go back to menu"]) check_grades = check_grades[0].lower() if check_grades == "yes": idx = codecooler_view.get_inputs("Please provide idx of the student", ["Idx"])[0] student_controller.view_grades(idx)
def get_message(): """ Get user massage to chat """ message = codecooler_view.get_inputs( '', ['\nLeave your message Or type 0 to exit'])[0] return message
def get_user_details(): """ Return detail about person Returns: list of strings: list of strings with details about person as fallow: password, Name, Surname, email Raises: ValueError: if person email have not proper format """ questions_list = ['password', 'Name', 'Surname', 'email'] user_details = [] for question in questions_list: user_input = None while not user_input: user_input = codecooler_view.get_inputs('', [question])[0] try: user_input = additional_filters_for_user_details( question, user_input) except ValueError as err: print(err) user_input = None user_details.append(user_input) today = date.today() today = "{}.{}.{}".format(today.day, today.month, today.year) user_details.append(today) return user_details
def modify_person_details(a_list, choosen_detail, title, task): """ Modify given information about person Args: a_list (list of :obj:): list of object representation of person choosen_detail (string): detail about person we want to change title (string): title of performed task task (list of strings): list that tell user what infromation should be provided Raises: ValueError: if person email have not proper format """ person = get_person(a_list, 'Choose person', ['Please provide person idx to modify']) if person: updated_information = codecooler_view.get_inputs(title, task)[0] try: updated_information = additional_filters_for_user_details( choosen_detail, updated_information) except ValueError as err: print(err) sleep(1.5) else: _modify_person_details_request(person, choosen_detail, updated_information)
def start_student_edit_menu(): """ Call functions that get user input and show inner menu to modify Student object or creat new Student object. Args: students (list of :obj: Student): list of all students """ user_request = None user_welcome = "Student edit manager" student_edit_menu = [ 'Add student', 'Delete student', 'Modify student name', 'Modify student surname', 'Modify student password', 'Modify student email' ] while user_request != "0": get_students_list(False) codecooler_view.print_menu(user_welcome, student_edit_menu, "Exit") user_request = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] handle_student_edit_requests(user_request) codecooler_view.clear_window()
def start_controller(students): """ Contain main logic for AssignmentController. Ask user about assigemnt details and add it to assigments list Args: students (list of :obj: `Student`): list of all students Raises: ValueError: if deadline date is wrong """ "is_empty = True" questions = ["Title", "Description"] deadline_questions = ["Deadline day", "Deadline month", "Deadline year"] assgn_details = codecooler_view.get_inputs("Add assignment", questions) deadline_details = codecooler_view.get_inputs("Provide deadline", deadline_questions) is_empty = is_empty_input(assgn_details) check_adding_assignment_possibility = is_possible_to_add_assignment( assgn_details[0]) if not is_empty and check_adding_assignment_possibility: try: deadline = set_deadline(*deadline_details) Assignment.assignments.append(Assignment(*assgn_details, deadline)) codecooler_view.print_result('Succesfuly added assignment.') _create_student_assigments(students, assgn_details[0]) except ValueError: codecooler_view.print_result("Provided deadline is impossible!") else: codecooler_view.print_error_message( 'Please provide title, description. Or Try another title.') sleep(2)
def _check_attendance(students_attendance, students): """ Create `AttendnaceModel` object with given student id, state and current date. Args: students_attendance (list of :obj: `AttendanceModels`): list with detail of attendance for all students students (list of :obj: `StudentModels`):list with detail of all students Examples: `AttendnaceModel` object have state as float representing presance of student during class in current day date. Presence with it's float value is as follow: Present: 1.0, Not present: 0.0 and Late: 0.8 """ current_date = str(date.today()) for student in students: try: _vaildate_correct_date(current_date, student, students_attendance) except ValueError as err: print(err) codecooler_view.state_locker() continue user_choice = None attendance_state = None check_attendance_person = "Check attendance for {} {}".format( student.name, student.surname) while user_choice not in ["0", "1", "2", "3"]: codecooler_view.print_menu(check_attendance_person, ["Present", "Not present", "Late"], "Exit") user_choice = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] attendance_values = {'1': '1.0', '2': '0.0', '3': '0.8'} if user_choice in attendance_values: attendance_state = attendance_values[user_choice] else: codecooler_view.print_error_message('Wrong option!') if attendance_state: student_attendance = AttendanceModel(student.idx, current_date, float(attendance_state)) students_attendance.append(student_attendance)
def start_controller(name, surname, idx): """ Allow mentor perform assign tasks. Call functions to print menu for user and get input of choosen option. Then call proper function to perform given task. Args: name (string): name of user surname (string): surname of user idx (string): unique user's id """ students = Student.get_students_list() option = None while option != "0": codecooler_view.clear_window() codecooler_view.print_menu("Welcome {} {}".format(name, surname), [ "Students list", "Add assignment", "Grade assignment", "Check attendace", "Edit student", "Student ranking", "Change your password", "Enter talkbox" ], "Exit") option = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] codecooler_view.clear_window() if option == "1": get_students_list(present_student_grades=True) elif option == "2": assignment_controller.start_controller(students) elif option == "3": show_assignments() submit_assignment_controller.start_controller("mentor", idx) elif option == "4": attendance_controller.start_controller(students) elif option == "5": start_student_edit_menu() elif option == "6": rank = student_controller.get_ranking() codecooler_view.print_table(["Name", "Total points"], rank) codecooler_view.state_locker() elif option == "7": codecooler_controller.change_password(idx) elif option == "8": talkbox.start_talkbox(name, surname)
def start_mentor_edit_menu(): """ Call functions that get user input and show inner menu with options to modification Mentor object or creat new Mentor object. """ mentor_edit_menu = ['Add mentor', 'Delete mentor', 'Modify mentor name', 'Modify mentor surname', 'Modify mentor password', 'Modify mentor email'] user_welcome = "Mentors edit manager" user_request = None while user_request != "0": codecooler_view.clear_window() get_mentors_list() codecooler_view.print_menu(user_welcome, mentor_edit_menu, "Exit") user_request = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] handle_mentor_edit_requests(user_request)
def start_controller(name, surname, idx): """ Allow student user perform assign tasks. Call functions to print menu for user and get input of choosen user_choice Args: name (string): name of user surname (string): surname of user idx (string): unique user's id """ user_choice = None while user_choice != "0": codecooler_view.clear_window() codecooler_view.print_menu("Welcome {} {}".format(name, surname), [ "Submit assignment", "View grades", "Students ranking", "Change your password", "Enter talkbox", "Debt calculator" ], "Exit") user_choice = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] codecooler_view.clear_window() if user_choice == "1": submit_assignment_controller.start_controller("student", idx) elif user_choice == "2": view_grades(idx) elif user_choice == "3": rank = get_ranking() codecooler_view.print_table(["Name", "Total points"], rank) codecooler_view.state_locker() codecooler_view.clear_window() elif user_choice == "4": codecooler_controller.change_password(idx) elif user_choice == "5": talkbox.start_talkbox(name, surname) elif user_choice == "6": show_debt(idx)
def change_password(idx): """ Allow user to change his password Args: idx (string): unique id of user """ user = find_user_by_id(idx) passes = codecooler_view.get_inputs("Please provide data", ["Old password", "New password"]) if passes[0] == user.password: user.password = passes[1] codecooler_view.print_result("Password changed succesfully!\n") else: codecooler_view.print_error_message('Wrong old password provided.') sleep(1.5) codecooler_view.clear_window()
def start_controller(name, surname, idx): """ Allow office manager perform assign tasks. Call functions to print menu for user and get input of choosen option: show students list, students ranking or use talkbox. Args: name (string): name of user surname (string): surname of user idx (strung): unique user idx """ user_choice = None while user_choice != "0": codecooler_view.print_menu("Welcome {} {}".format(name, surname), ["Show student list", "Students ranking", "Change your password", "Enter talkbox"], "Exit") user_choices = codecooler_view.get_inputs("Please choose a number", ["Number"]) user_choice = user_choices[0] handle_menu(user_choice, idx, name, surname)
def start_controller(name, surname, idx): """ Call functions that get user input and show menu Args: name (string): name of user surname (string): surname of user idx (string): unique user's id """ user_welcome = "Welcome {} {}".format(name, surname) main_menu = ['List mentors', 'Edit mentors', 'List Students', "Students ranking", 'Change your password', "Enter talkbox"] user_request = None while user_request != "0": codecooler_view.clear_window() codecooler_view.print_menu(user_welcome, main_menu, "Exit") user_request = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] codecooler_view.clear_window() handle_main_menu_requests(user_request, idx, name, surname)
def login(): """ Contain logic of user login to program. Create list of all users and check if user login and password are correct. """ found = False data_loader.load_data_from_files() mergedlist = Student.student_list + Mentor.mentor_list + OfficeManager.office_managers_list + Manager.manager_list while not found: passes = codecooler_view.get_inputs( "Please provide your login and password", ["Login", "Password"]) idx, password = passes[0], passes[1] for ccooler in mergedlist: if idx == ccooler.idx and password == ccooler.password: codecooler_view.clear_window() start_controller(ccooler) found = True break if not found: codecooler_view.print_result("Wrong login or password!\n")
def get_person(a_list, title, task): """ Check by person's id if person is on list. Args: a_list (list of :obj:): list of object representation of person title (string): title of performed task task (list of strings): list that tell user what infromation should be provided """ idx = codecooler_view.get_inputs(title, task)[0] person = None for homie in a_list: if homie.idx == idx: person = homie break if person: return person else: print('Not found person!') sleep(1.5)