def __init__(self, repository): ''' Constructor ''' self.__today = date.today() self.__assign_repository = Assignment_repository() self.__assign_validator = Assignment_validator()
class Test_Assignment_repository(TestCase): def setUp(self): super().setUp() self.__repository = Assignment_repository() def test_add_student(self): assignment = Assignment(1, "fain", "23 12 1996", 10) self.__repository.add_assignment(assignment) self.assertEqual(len(self.__repository.list_all_assignments()), 1, "There should be 1 assignment in the test repository!")
def __init__(self, repository): ''' Constructor ''' self.__grade_repository = Grade_repository() self.__grade_validator = Grade_validator() self.__stud_repository = Student_repository() self.__assign_repository = Assignment_repository()
class Assignment_controller: ''' classdocs ''' def __init__(self, repository): ''' Constructor ''' self.__assign_repository = Assignment_repository() self.__assign_validator = Assignment_validator() def add_assignment(self,assign_id,description,deadline,grade): assign = Assignment(assign_id,description,deadline,grade) self.__assign_validator.validate_assignment(assign) self.__assign_repository.add_assignment(assign) def add_sample_data(self): self.add_assignment(1,"ass1","20/1",2) self.add_assignment(2,"ass2","21/2",2) self.add_assignment(3,"ass3","22/3",2) self.add_assignment(4,"ass4","23/4",2) self.add_assignment(5,"ass5","24/5",2) self.add_assignment(6,"ass6","25/6",2) self.add_assignment(7,"ass7","26/7",2) self.add_assignment(8,"ass8","27/8",2) self.add_assignment(9,"ass9","28/9",2) self.add_assignment(10,"ass10","29/10",2) def update_assignment(self,assign_id,description,deadline): assign = Assignment(assign_id,description,deadline) self.__assign_validator.validate_assignment(assign) self.__assign_repository.update_assignment(assign) def remove_assignment(self,assign_id,description,deadline,grade): assign = Assignment(assign_id,description,deadline,grade) self.__assign_validator.validate_assignment(assign) self.__assign_repo.remove_assignment(assign) def remove_assignment_by_id(self,assign_id): self.__assign_repository.remove_assignment(assign_id) def find_assignment_by_id(self,assign_id): return self.__assign_repository.find_assignment(assign_id) def assignments_length(self): return self.__assign_repository.assignments_length() def list_all_assignments(self): return self.__assign_repository.list_all_assignments()
class Assignment_controller: ''' classdocs ''' def __init__(self, repository): ''' Constructor ''' self.__assign_repository = Assignment_repository() self.__assign_validator = Assignment_validator() def add_assignment(self, assign_id, description, deadline, grade): assign = Assignment(assign_id, description, deadline, grade) self.__assign_validator.validate_assignment(assign) self.__assign_repository.add_assignment(assign) def update_assignment(self, assign_id, description, deadline): assign = Assignment(assign_id, description, deadline) self.__assign_validator.validate_assignment(assign) self.__assign_repository.update_assignment(assign) def remove_assignment(self, assign_id, description, deadline, grade): assign = Assignment(assign_id, description, deadline, grade) self.__assign_validator.validate_assignment(assign) self.__assign_repo.remove_assignment(assign) def remove_assignment_by_id(self, assign_id): self.__assign_repository.remove_assignment(assign_id) def find_assignment_by_id(self, assign_id): return self.__assign_repository.find_assignment(assign_id) def assignments_length(self): return self.__assign_repository.assignments_length() def list_all_assignments(self): return self.__assign_repository.list_all_assignments()
''' Created on Nov 3, 2016 @author: AndreiMsc ''' from repository.Student_repository import Student_repository from controller.Student_controller import Student_controller from repository.Assignment_repository import Assignment_repository from controller.Assignment_controller import Assignment_controller from repository.Grade_repository import Grade_repository from controller.Grade_controller import Grade_controller from ui.Commands import Commands from ui.Menu import Menu from ui.ui_Selector import ui_Selector stud_repo = Student_repository() stud_ctrl = Student_controller(stud_repo) assign_repo = Assignment_repository() assign_ctrl = Assignment_controller(assign_repo) grade_repo = Grade_repository() grade_ctrl = Grade_controller(grade_repo) method = ui_Selector.ui_selector() if method == "command": com = Commands(stud_ctrl,assign_ctrl,grade_ctrl) com.ui_run() else: menu = Menu(stud_ctrl,assign_ctrl,grade_ctrl) menu.ui_run()
def setUp(self): super().setUp() self.__repository = Assignment_repository()
class Assignment_controller: ''' classdocs ''' def __init__(self, repository): ''' Constructor ''' self.__today = date.today() self.__assign_repository = Assignment_repository() self.__assign_validator = Assignment_validator() def add_assignment(self, assign_id, description, deadline, grade): assign = Assignment(assign_id, description, deadline, grade) self.__assign_validator.validate_assignment(assign) self.__assign_repository.add_assignment(assign) def add_sample_data(self): self.add_assignment(1, "ass1", "20 1 2013", 2) self.add_assignment(2, "ass2", "21 1 2014", 2) self.add_assignment(3, "ass3", "22 1 2015", 2) self.add_assignment(4, "ass4", "23 1 2016", 2) self.add_assignment(5, "ass5", "24 1 2017", 2) self.add_assignment(6, "ass6", "25 1 2018", 2) self.add_assignment(7, "ass7", "26 1 2019", 2) self.add_assignment(8, "ass8", "27 1 2020", 2) self.add_assignment(9, "ass9", "28 1 2021", 2) self.add_assignment(10, "ass10", "29 1 2022", 2) 1 def update_assignment(self, assign_id, description, deadline, grade): assign = Assignment(assign_id, description, deadline, grade) self.__assign_validator.validate_assignment(assign) self.__assign_repository.update_assignment(assign) def remove_assignment_by_id(self, assign_id): self.__assign_repository.remove_assignment_by_id(assign_id) def find_assignment_by_id(self, assign_id): assign_with_id = self.__assign_repository.find_assignment(assign_id) return assign_with_id def assignments_length(self): return self.__assign_repository.assignments_length() def list_all_assignments(self): return self.__assign_repository.list_all_assignments() def find_id(self, assign_id): return self.__assign_repository.find_id(assign_id) def possible_late(self): possible_late = [] for assign in self.__assign_repository.list_all_assignments(): assign.deadline = assign.deadline.split(' ') assign_deadline = date(int(assign.deadline[2]), int(assign.deadline[1]), int(assign.deadline[0])) if self.__today > assign_deadline: possible_late.append(assign.assign_id) return possible_late
class Assignment_controller: ''' Controls assignments repository ''' def __init__(self, repository): ''' Constructor ''' self.__today = date.today() self.__assign_repository = Assignment_repository() self.__assign_validator = Assignment_validator() def add_assignment(self, assign_id, description, deadline, grade): ''' Adds a new assignment to the repository after validating its properties Input: :param assign_id :param description :param deadline :param grade ''' assign = Assignment(assign_id, description, deadline, grade) self.__assign_validator.validate_assignment(assign) self.__assign_repository.add_assignment(assign) def add_sample_data(self): ''' Adds sample assignments to the repository ''' self.add_assignment(1, "ass1", "20 1 2013", 2) self.add_assignment(2, "ass2", "21 1 2014", 2) self.add_assignment(3, "ass3", "22 1 2015", 2) self.add_assignment(4, "ass4", "23 1 2016", 2) self.add_assignment(5, "ass5", "24 1 2017", 2) self.add_assignment(6, "ass6", "25 1 2018", 2) self.add_assignment(7, "ass7", "26 1 2019", 2) self.add_assignment(8, "ass8", "27 1 2020", 2) self.add_assignment(9, "ass9", "28 1 2021", 2) self.add_assignment(10, "ass10", "29 1 2022", 2) 1 def update_assignment(self, assign_id, description, deadline, grade): ''' Updates an assignment from the repository after validating its new properties Input: :param assign_id :param description :param deadline :param grade ''' assign = Assignment(assign_id, description, deadline, grade) self.__assign_validator.validate_assignment(assign) self.__assign_repository.update_assignment(assign) def remove_assignment_by_id(self, assign_id): ''' Removes the assignment with the given ID from the repository Input: :param assign_id ''' self.__assign_repository.remove_assignment_by_id(assign_id) def find_assignment_by_id(self, assign_id): ''' Finds the assignment with the given ID Input: :param assign_id Output: :return assign_with_id ''' assign_with_id = self.__assign_repository.find_assignment(assign_id) return assign_with_id def assignments_length(self): ''' Returns the number of assignments Output: :return self.__assign_repository.assignments_length() ''' return self.__assign_repository.assignments_length() def list_all_assignments(self): ''' Makes a list containing all assignments Output: :return self.__assign_repository.list_all_assignments() ''' return self.__assign_repository.list_all_assignments() def find_id(self, assign_id): ''' Check if the assignment with the given ID exists Input: :param assign_id Output: :return self.__assign_repository.find_id(assign_id) ''' return self.__assign_repository.find_id(assign_id) def possible_late(self): ''' Makes a list containing all IDs of assignments which have the deadline passed, so which could be late Output: :return possible_late ''' possible_late = [] for assign in self.__assign_repository.list_all_assignments(): assign.deadline = assign.deadline.split(' ') assign_deadline = date(int(assign.deadline[2]), int(assign.deadline[1]), int(assign.deadline[0])) if self.__today > assign_deadline: possible_late.append(assign.assign_id) return possible_late