Example #1
0
    def get(self):
        print ""
                
        combinations = db.GqlQuery("SELECT * FROM Combination WHERE class_id >= :1 AND class_id < :2", "3", u"3" + u"\ufffd").fetch(9999)
        combinations.extend(db.GqlQuery("SELECT * FROM Combination WHERE class_id >= :1 AND class_id < :2", "4", u"4" + u"\ufffd").fetch(9999))
        
        # All teachers that are assigned to a subject
        workingTeachers = [];
        
        for comb in combinations:
            workingTeachers.append(comb.teacher.key().name())
        
        workingTeachers = Set(workingTeachers)
        workingTeachers = list(workingTeachers)

        
        # Teachers not assigned to a subject        
        temp = Teacher.all().fetch(9999)
        otherTeachers = [teacher.key().name() for teacher in temp]
        
        for teacher in workingTeachers:
            otherTeachers.remove(teacher)
        
        groupA = otherTeachers[:40]
        groupB = otherTeachers[37:]

        
        # Get all combinations for years 3 and 4
        
        combinations = db.GqlQuery("SELECT * FROM Combination WHERE class_id >= :1 AND class_id < :2", "3", u"3" + u"\ufffd").fetch(9999)
        combinations.extend(db.GqlQuery("SELECT * FROM Combination WHERE class_id >= :1 AND class_id < :2", "4", u"4" + u"\ufffd").fetch(9999))
        
        print "Conversion for years 3 and 4:"
        
        for comb in combinations:
            oldTeacher = comb.teacher.key().name()
            oldTeacherIndex = workingTeachers.index(oldTeacher)
            newTeacherKey = groupA[oldTeacherIndex]
            newTeacher = Teacher.all().filter("__key__", Key.from_path('Teacher',newTeacherKey)).get()
            print "old: "+oldTeacher+" - new: "+newTeacher.key().name()
            comb.teacher = newTeacher
            comb.save()
        
        
        # Get all combinations for years 5 and 6
        
        combinations = db.GqlQuery("SELECT * FROM Combination WHERE class_id >= :1 AND class_id < :2", "5", u"5" + u"\ufffd").fetch(9999)
        combinations.extend(db.GqlQuery("SELECT * FROM Combination WHERE class_id >= :1 AND class_id < :2", "6", u"6" + u"\ufffd").fetch(9999))
        
        # All teachers that are assigned to a subject
        workingTeachers = [];
        
        for comb in combinations:
            workingTeachers.append(comb.teacher.key().name())
        
        workingTeachers = Set(workingTeachers)
        workingTeachers = list(workingTeachers)        
        
        combinations = db.GqlQuery("SELECT * FROM Combination WHERE class_id >= :1 AND class_id < :2", "5", u"5" + u"\ufffd").fetch(9999)
        combinations.extend(db.GqlQuery("SELECT * FROM Combination WHERE class_id >= :1 AND class_id < :2", "6", u"6" + u"\ufffd").fetch(9999))
        
        
        print "Conversion for years 5 and 6:"
        
        for comb in combinations:
            oldTeacher = comb.teacher.key().name()
            oldTeacherIndex = workingTeachers.index(oldTeacher)
            newTeacherKey = groupB[oldTeacherIndex]
            newTeacher = Teacher.all().filter("__key__", Key.from_path('Teacher',newTeacherKey)).get()
            print "old: "+oldTeacher+" - new: "+newTeacher.key().name()
            comb.teacher = newTeacher
            comb.save()
Example #2
0
    def get(self):
        
        # Load all Guardians
        path = os.path.join(os.path.dirname(__file__), 'data/voogdouder.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_guardian = Guardian(key_name=row[0].strip())
            new_guardian.title=row[1].strip()
            new_guardian.initials=row[2].strip()
            new_guardian.preposition=row[3].strip()
            new_guardian.lastname=row[4].strip()
            new_guardian.streetname=row[6].strip()
            new_guardian.housenumber=row[7].strip()
            new_guardian.city=row[8].strip()
            new_guardian.postalcode=row[9].strip()
            new_guardian.email=row[12].strip()
            new_guardian.save()
            print "Guardian " + new_guardian.key().id_or_name() + " stored"

        # Load all Students
        path = os.path.join(os.path.dirname(__file__), 'data/leerlingen.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_student = Student(key_name=row[0].strip())
            new_student.firstname=row[1].strip()
            new_student.preposition=row[2].strip()
            new_student.lastname=row[3].strip()
            new_student.gender=row[4].strip()
            new_student.class_id=row[5].strip()
            new_student.guardian=Guardian.all().filter("__key__ >=", Key.from_path('Guardian', row[6].strip())).get()
            new_student.save()
            print "Student " + new_student.key().id_or_name() + " stored"
            
        # Load all Teachers
        path = os.path.join(os.path.dirname(__file__), 'data/docenten.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader:
            new_teacher = Teacher(key_name=row[0].strip())
            new_teacher.name=row[1].strip()
            new_teacher.boxnumber=int(row[2].strip())
            new_teacher.email=row[3].strip()
            new_teacher.save()
            print "Teacher " + new_teacher.key().id_or_name() + " stored"
            
        # Load all Subjects
        path = os.path.join(os.path.dirname(__file__), 'data/vakken.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader:
            new_subject = Subject(key_name=row[0].strip())
            new_subject.name=row[1].strip()
            new_subject.save()
            print "Subject " + new_subject.key().id_or_name() + " stored"

        # Load all Students
        path = os.path.join(os.path.dirname(__file__), 'data/docent_vak.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_combination = Combination()
            new_combination.class_id=row[0].strip()
            new_combination.subject=Subject.all().filter("__key__ >=", Key.from_path('Subject', row[1].strip())).get()
            new_combination.teacher=Teacher.all().filter("__key__ >=", Key.from_path('Teacher', row[2].strip())).get()
            new_combination.save()
            print "Combination " + str(new_combination.key().id_or_name()) + " stored"
        self.redirect("/fix")