def grade_assignment(): ''' Prints the list of students to choose a student. Then prints assignments of the student. Then asks the user for the choice and changing the grade. ''' if Student.list_of_students == []: return mentor_view.print_empty_database_msg() view_students() student_index = get_student_index() if student_index is not None: assignment_controller.print_student_assignments(student_index) assignment = assignment_controller.get_assignment_form_user_input() if assignment: solution = assignment.solutions[student_index] if solution.can_be_graded: view.print_message(solution.get_content()) solution.grade = get_new_grade(assignment.max_grade) Assignment.save_assignments_to_file('assignments.csv') else: mentor_view.assignment_already_graded() else: mentor_view.no_such_assignment() else: mentor_view.index_doesnt_exist()
def load_database(): ''' Initialize all objects stored in data/.. Close program if there is not enough database to function properly. Parameters, Returns: None Initialize: Student objs. Mentor objs. Employee objs. Manager objs. Assigments objs. Logins.list_of_logins ''' Assignment.get_assignments_from_file('assignments.csv') Attendance.get_attendance_from_file('attendance.csv') Student.get_codecoolers_from_file('students.csv') Employee.get_codecoolers_from_file('employees.csv') Mentor.get_codecoolers_from_file('mentors.csv') Manager.get_codecoolers_from_file('managers.csv') if len(Manager.list_of_managers) < 1 or len( Employee.list_of_employees) < 1: err_msg = 'There is no database stored. Contact our support at [email protected]' view.print_message(err_msg) sys.exit() Logins.from_codecoolers(Student.list_of_students, Employee.list_of_employees, Manager.list_of_managers, Mentor.list_of_mentors)
def check_attendance(): ''' Prints the name of the student if he hasn't been checked today. Adds his attendance for today based on input. Updates attendance list and saves to file. ''' title, exit_message, options = mentor_view.data_to_check_attendance() students = Student.list_of_students attendances = Attendance.list_of_attendance for student in students: if datetime.date.today() not in [ att.date for att in attendances if att.student_login == student.login ]: os.system('clear') fullname = student.name + ' ' + student.surname view.print_message(fullname) view.print_menu(title, options, exit_message) option = get_option(options) if option == 4: # skips a student continue elif option == 0: break # breaks checking for now update_attendance(option, student, attendances) show_attendance_status(students, attendances)
def edit_assignment(): ''' Lets user choose Assignemnt obj. and change it's attribiutes values Paramaters: None Returns: None Updates: Assignemnt obj. ''' print_assignments() assignment = get_assignment_form_user_input() if assignment: name, deadline, max_grade = get_valid_inputs() deadline = format_date(deadline) assignment.name = name assignment.deadline = deadline assignment.max_grade = max_grade Assignment.save_assignments_to_file('assignments.csv') else: no_assignment_message = assignment_view.get_no_assignment_message() view.print_message(no_assignment_message)
def get_new_grade(max_grade): ''' Asks the user to enter the new grade. Checks if it's positive int and not greater than max_grade. Args: max_grade (int) - max possible grade of assignment Returns: new_grade (int) - new grade to change to ''' new_grade = None while new_grade not in range(0, max_grade + 1): view.print_message("Please provide new grade value.") new_grade = view.input_number() return new_grade
def change_password(user): ''' Get old password from user and if is correct, change password for new. If is incorrect, print error message. Args: user - object Returns: None ''' old_password = view.get_inputs(['Old password'], 'Type your old password')[0] if old_password == user.password: new_password = view.get_inputs(['New password'], 'Type your new password')[0] user.password = new_password else: view.print_message('Bad old password')
def submit_assigment(student): ''' Choose assignment from list and change status assignment 'done'. Save change to file' Args: student - obj ''' student_index = Student.list_of_students.index(student) view_grades(student) number = None while not number: number = view.input_number() if number <= Assignment.amount_of_assignments(): assignment = Assignment.list_of_assignments[number - 1] assignment_controller.submit_solution_to_assignment(assignment, student_index) Assignment.save_assignments_to_file('assignments.csv') else: text = view_student.get_invalid_assignment_in_submit() view.print_message(text)
def mentor_menu(user): ''' Prints user specific features and asks him for operation to perform. Resolve all interactions, util user diecides to exit. Returns: None ''' title, exit_message, options = mentor_view.menu_labels(user) end = False while not end: view.print_menu(title, options, exit_message) option = view.input_number() if option == 1: view_students() view.print_message("Press any key to continue.") view.wait_until_key_pressed() elif option == 2: assignment_controller.create_assignment() elif option == 3: assignment_controller.edit_assignment() elif option == 4: grade_assignment() elif option == 5: check_attendance() elif option == 6: add_student() elif option == 7: remove_student() elif option == 8: change_password(user) elif option == 0: end = True
def print_fail_message(): view.print_message('\nChosen assignment was already submited.\n')