예제 #1
0
    def addAll(self, jsonData):
        s = ConnectDb.session()

        print (type(s))

        objectFormater = ObjectFormater("wesh")

        offenders = objectFormater.OffendersToObjects(jsonData["offenders"])
        grades = objectFormater.GradesToObjects(jsonData["grades"])
        cops = objectFormater.CopsToObjects(jsonData["cops"])
        lessons = objectFormater.LessonsToObjects(jsonData["lessons"])
        lessons_grades = objectFormater.LessonsGradesToObjects(jsonData["lessons"])
        classrooms = objectFormater.ClassroomsToObjects(jsonData["classrooms"])

        for grade in grades:
            s.merge(grade)
        s.commit()
        for classroom in classrooms:
            s.merge(classroom)
        s.commit()
        for cop in cops:
            s.merge(cop)
        s.commit()
        for offender in offenders:
            s.merge(offender)
        s.commit()
        for lesson in lessons:
            s.merge(lesson)
        s.commit()
        for lessons_grade in lessons_grades:
            s.merge(lessons_grade)
        s.commit()
예제 #2
0
    def getByLesson(self, idLesson):
        s = ConnectDb.session()

        offender = s\
            .query(Offender).select_from(Grade)\
            .filter(Offender.id == id)\
            .join(Offender.grade)\
            .one()
예제 #3
0
    def getByMac(self, mac):

        s = ConnectDb.session()

        cop = s\
            .query(Cop)\
            .filter(Cop.mac_address == mac)\
            .all()
        return cop
예제 #4
0
    def getLessonByTeacherAndByDate(self, idTeacher, date):
        s = ConnectDb.session()

        lesson = s.query(Lesson)\
            .join(Offender.lesson)\
            .filter(Offender.id == idTeacher)\
            .filter(Lesson.date == date)\
            .all()

        return lesson
예제 #5
0
    def getByStudy(self, idStudy):
        s = ConnectDb.session()

        lesson = s.query(Lesson)\
            .join(Offender.grade)\
            .join(Lesson_grade)\
            .join(Lesson)\
            .filter(Offender.id == idStudy)\
            .one()

        return lesson
예제 #6
0
    def getByIdWithGrade(self, id):

        s = ConnectDb.session()

        offender = s\
            .query(Offender).select_from(Grade)\
            .filter(Offender.id == id)\
            .join(Offender.grade)\
            .one()

        return offender
예제 #7
0
파일: Fixture.py 프로젝트: Maxsky5/COPS-COP
    def testAddWithLink(self):

        # connexion db
        session = ConnectDb.session()

        ril_grade = Grade(name="ril", date_start='20140901', date_end='20160901', date_update=time.strftime("%Y%m%d"))
        thomas = Offender(id=1, firstname='thomas', lastname='peyrou', email='*****@*****.**', date_update=time.strftime("%Y%m%d"), type=2, grade=ril_grade)

        session.add(thomas)
        session.add(ril_grade)
        session.commit()
예제 #8
0
    def getLessonByGradeAndByDate(self, idGrade, date):
        s = ConnectDb.session()

        lesson = s.query(Lesson)\
            .join(Offender.grade)\
            .join(Lesson_grade)\
            .join(Lesson)\
            .filter(Offender.grade_id == idGrade)\
            .filter(Lesson.date == date)\
            .all()

        return lesson
예제 #9
0
    def getByMacAndByLesson(self, mac, idLesson):

        s = ConnectDb.session()

        cop = s\
            .query(Cop)\
            .join(Classroom)\
            .join(Lesson)\
            .filter(Cop.mac_address == mac)\
            .filter(Lesson.id == idLesson)\
            .all()

        return cop
예제 #10
0
파일: Fixture.py 프로젝트: Maxsky5/COPS-COP
    def deleteRecords(self):

        # connexion base
        session = ConnectDb.session()

        session.query(Lesson_grade).delete()
        session.query(Lesson).delete()
        session.query(Check).delete()
        session.query(Offender).delete()
        session.query(Cop).delete()

        session.query(Classroom).delete()
        session.query(Grade).delete()

        session.commit()
예제 #11
0
    def getById(self, id):
        s = ConnectDb.session()

        lesson = s.query(Lesson).filter(Lesson.id == id).one()
        return lesson
예제 #12
0
    def add(self, check):

        s = ConnectDb.session()
        s.add(check)
        s.commit()
        print "checked !"
예제 #13
0
    def getAll(self):
        s = ConnectDb.session()

        checks = s.query(Check).all()
        return checks
예제 #14
0
    def getById(self, id):
        s = ConnectDb.session()

        offender = s.query(Offender).filter(Offender.id == id).all()

        return offender
예제 #15
0
    def getById(self, id):
        s = ConnectDb.session()

        cop = s.query(Cop).filter(Cop.id == id).one()
        return cop
예제 #16
0
파일: Fixture.py 프로젝트: Maxsky5/COPS-COP
    def addRecords(self):

        # connexion db
        session = ConnectDb.session()

        # checks
        check1 = Check(date=time.strftime("%Y%m%d"))

        # offenders
        thomas = Offender(firstname='thomas', lastname='peyrou', email='*****@*****.**', date_update=time.strftime("%Y%m%d"), type=2)
        maxime = Offender(firstname='maxime', lastname='ribera', email='', date_update=time.strftime("%Y%m%d"), type=2)
        arthur = Offender(firstname='arthur', lastname='sore', email='', date_update=time.strftime("%Y%m%d"), type=2)
        adam = Offender(firstname='adam', lastname='dief', email='', date_update=time.strftime("%Y%m%d"), type=2)
        gerard = Offender(firstname='gerard', lastname='bboulet', email='*****@*****.**', date_update=time.strftime("%Y%m%d"), type=2)
        stephan = Offender(firstname='stephan', lastname='amet', email='', date_update=time.strftime("%Y%m%d"), type=1)
        pere_fourasse = Offender(firstname='jeanpaul', lastname='fourasse', email='', date_update=time.strftime("%Y%m%d"), type=1)

        # grades
        ril_grade = Grade(name="ril", date_start='20140901', date_end='20160901', date_update=time.strftime("%Y%m%d"))
        rar_grade = Grade(name="rar", date_start='20140901', date_end='20160901', date_update=time.strftime("%Y%m%d"))

        # Cops
        cop_1 = Cop(name='Cop001', date_update=time.strftime("%Y%m%d"), date_last_sync=time.strftime("%Y%m%d"), mac_address='00:00:00:00:00:00')
        cop_2 = Cop(name='Cop002', date_update=time.strftime("%Y%m%d"), date_last_sync=time.strftime("%Y%m%d"), mac_address='11:11:11:11:11:11')

        # Lessons
        lesson_soulac = Lesson(date=time.strftime("%Y%m%d"), is_morning=0, date_update=time.strftime("%Y%m%d"))
        lesson_brive = Lesson(date=time.strftime("%Y%m%d"), is_morning=1, date_update=time.strftime("%Y%m%d"))

        # Classrooms & Add lesson
        soulac_classroom = Classroom(name='soulac', nb_place=20, lesson=lesson_soulac, date_update=time.strftime("%Y%m%d"))
        brive_classroom = Classroom(name='brive', nb_place=20, lesson=lesson_brive, date_update=time.strftime("%Y%m%d"))

        # add offenders to grade
        ril_grade.offenders = ([thomas, maxime, arthur, adam])
        rar_grade.offenders = ([gerard])



        # add cop to classroom
        soulac_classroom.cops = [cop_1]
        brive_classroom.cops = [cop_2]

        # add lesson to offender (type teacher)
        stephan.lesson = lesson_soulac
        pere_fourasse.lesson = lesson_brive

        # add check to offencer
        thomas.check = [check1]

        # add check to cop
        cop_1.check = [check1]

        # add grade & lesson to Lesson_grade
        lesson_ril = Lesson_grade(lesson=lesson_soulac, grade=ril_grade)
        lesson_rar = Lesson_grade(lesson=lesson_brive, grade=rar_grade)

        session.add_all([lesson_ril])
        session.add_all([lesson_rar])
        session.commit()

        return "Record added !"