Exemple #1
0
 def __init__(self, studid, name, group):
     if len(studid) == 0:
         raise StudentError("Bad ID")
     if len(name) == 0:
         raise StudentError("Invalid Name")
     self.studid = studid
     self.name = name
     self.group = group
Exemple #2
0
 def setName(self, newname):
     '''
     Updates the name of a given student, replacing the name of this student with the string newname
     '''
     if len(newname) == 0:
         raise StudentError("Invalid Name")
     self.name = newname
Exemple #3
0
 def setID(self, newid):
     '''
     Updates the ID of a given student, replacing the ID with the string newid
     '''
     if len(newid) == 0:
         raise StudentError("Bad ID")
     self.studid = newid
Exemple #4
0
 def removeById(self, idstring):
     '''
     removes the assignment having the given ID
     '''
     for counter in range(0, len(self)):
         if self._data[counter].getKeyID() == idstring:
             return self._data.pop(counter)
     raise StudentError("Assignment not found")
Exemple #5
0
 def findByStudID(self, idstring):
     '''
     returns the assignment with the given student id
     '''
     for counter in range(0, len(self)):
         if self._data[counter].getID() == idstring:
             return self._data.pop(counter)
     raise StudentError("Assignment not found")
Exemple #6
0
 def add(self, Student):
     '''
     adds a new student to the repository
     input: Student object
     '''
     if self.findById(Student.getID()) != None:
         raise StudentError("Duplicate ID")
     else:
         self._data.append(Student)
Exemple #7
0
 def opt3(self):
     '''
     finds a student by ID
     '''
     print("Give  ID:")
     sid = input()
     if(len(self._sthandler._studrepo) == 0):
         raise StudentError ("No students in the list")
     print(self._sthandler.findStud(sid))        
Exemple #8
0
 def remove(self, Student):
     '''
     removes a student based on it's object. uses removeById method
     input: Student - the object to be removed
     no output
     '''
     if self.findById(Student.getID()) == None:
         raise StudentError("Student ID not found; cannot delete")
     else:
         return (self.removeById(Student.getID()))
Exemple #9
0
 def opt15(self):
     try:
         switch = self._redoswitch.pop()
     except:
         raise StudentError("No operation to redo!")
     if switch == 0:
         self._sthandler.redo()
     elif switch == 1:    
         self._ashandler.redo()
     self._undoswitch.append(switch)
Exemple #10
0
 def opt4(self):
     '''
     finds an assignment by ID
     '''
     print("Give  ID:")
     kid = input()
     temp = deepcopy(self._ashandler.findAssign(kid))
     if(temp == None):
         raise StudentError("No assignments in the list")
     print(temp)  
Exemple #11
0
 def updateById(self, studid):
     '''
     updates certain info of a student
     '''
     a = self.findIndex(self.findById(studid))
     if a == None or self.findById(studid) == None:
         raise StudentError("Student not found")
     print("Input new name:")
     self._data[a].setName(input())
     print("Input new group:")
     self._data[a].setGroup(int(input()))
     return self._data[a]
Exemple #12
0
 def removeById(self, idstring):
     '''
     removes a student from the repo based on the id
     input: the ID of the student wanting to be removed
     output: the Student object that has been removed
     '''
     temp = None
     for counter in range(0, len(self._data)):
         if self._data[counter - 1].getID() == idstring:
             temp = self._data.pop(counter - 1)
     if temp == None:
         raise StudentError("Student to be removed not found!")
     else:
         return temp
Exemple #13
0
 def updateByID(self, kid):
     temp = self.findById(kid)
     if temp == None:
         raise StudentError("No assignment found")
     '''
     Updates the deadline, grade and description of an assignment, finding it by its ID
     '''
     print("Input new Deadline:")
     temp.setDead(input())
     print("Input new Grade:")
     temp.setGrade(int(input()))
     print("Input new Description")
     temp.setDesc(input())
     return temp
Exemple #14
0
 def opt2(self):
     '''
     adds an assignment
     '''
     newassign = self._ashandler.addAssign()
     tempstud = self._sthandler.findStud(newassign.getID())
     if tempstud == None:
         self._ashandler.removeAssign(newassign.getID()) #removes object if there is no student to assign to
         raise StudentError("No student to assign to")
     else:
         self._linkhandler.makeLink(newassign,tempstud)
         print("Adding Successful")
     self._undoswitch.append(1)
     self._redoswitch = []
Exemple #15
0
 def takeInput(self):
     '''
     Takes input and calls controllers
     '''
     
     while True:
         self.showMain()
         opt = input()
            
         if opt == '1':
             self.opt1()    
         elif opt == '2':
             self.opt2() 
         elif opt == '3':
             self.opt3() 
         elif opt == '4':
             self.opt4()
         elif opt == '5':
             self.opt5()
         elif opt == '6':
             self.opt6()    
         elif opt == '7':
             self.opt7()
         elif opt == '8':
             self.opt8()
         elif opt =='9':
             self.opt9()
         elif opt =='10':
             self.opt10()
         elif opt == '11':
             self.opt11()
         elif opt == '12': 
             self.opt12()   
         elif opt == '15': #used to show links, lol
             templist = self._linkhandler.printLinks()
             for cr in range (0,len(templist)):
                 print(str(templist[cr]))
         elif opt =='13':
             self.opt14()
         elif opt =='14':
             self.opt15()
                 
         elif opt == '0':
             return 0
         else:
             raise StudentError("Invalid Command")
         
         self._ashandler._assignrepo.writetofile()
         self._sthandler._studrepo.writetofile()    
Exemple #16
0
 def sortStudentsABC(self, listStud, listAssign):
     '''
     Sorts a list of Student objects alphabetically
     input: listStud - list of students
     output: listStud - list of students (sorted)
     '''
     if len(listStud) <= 0 or len(listAssign) <= 0:
         raise StudentError("No students or no assignments")
     for counter in range(0, len(listStud)):
         for counter2 in range(counter, len(listStud)):
             if listStud[counter].getName() > listStud[counter2].getName():
                 aux = listStud[counter]
                 listStud[counter] = listStud[counter2]
                 listStud[counter2] = aux
     return listStud
Exemple #17
0
    def redo(self):
        if self._redoop == []:
            raise StudentError("No operations to redo")
        operation = self._redoop.pop()

        if isinstance(operation, AddOperation):
            self._studrepo.add(operation.getObject())

        elif isinstance(operation, RemoveOperation):
            self._studrepo.remove(operation.getObject())

        elif isinstance(operation, UpdateOperation):
            self._studrepo.remove(operation.getOldObject())
            self._studrepo.add(operation.getNewObject())

        self._undoop.append(operation)
Exemple #18
0
 def addStud(self):
     '''
     adds a new student to the repository
     calls add function in the repository
     '''
     print("Student Name:")
     tempName = input()
     print("Student ID:")
     tempID = input()
     print("Student Group:")
     try:
         tempGroup = int(input())
     except:
         raise StudentError("Invalid group!")
     newStud = Student(tempID, tempName, tempGroup)
     self._studrepo.add(newStud)
     self._undoop.append(AddOperation(newStud))
     self._redoop = []
Exemple #19
0
 def undo(self):
     if self._undoop < 0:
         raise StudentError("No operations to undo")
     operation = self._undoop.pop()
     if isinstance(operation, AddLink):
         operation.getRepo().removeLink(operation.getLink())