def coteachers(self, request, tl, one, two, module, extra, prog):
        if not 'clsid' in request.POST:
            return self.goToCore(tl)  # just fails.

        if extra == 'nojs':
            ajax = False
        else:
            ajax = True

        classes = ClassSubject.objects.filter(id=request.POST['clsid'])
        if len(classes) != 1 or not request.user.canEdit(classes[0]):
            return render_to_response(self.baseDir() + 'cannoteditclass.html',
                                      request, {})

        cls = classes[0]

        # set txtTeachers and coteachers....
        if not 'coteachers' in request.POST:
            coteachers = cls.get_teachers()
            coteachers = [
                user for user in coteachers if user.id != request.user.id
            ]

            txtTeachers = ",".join([str(user.id) for user in coteachers])

        else:
            txtTeachers = request.POST['coteachers']
            coteachers = txtTeachers.split(',')
            coteachers = [x for x in coteachers if x != '']
            coteachers = [
                ESPUser.objects.get(id=userid) for userid in coteachers
            ]
            add_list_members(
                "%s_%s-teachers" % (prog.program_type, prog.program_instance),
                coteachers)

        op = ''
        if 'op' in request.POST:
            op = request.POST['op']

        conflictingusers = []
        error = False

        if op == 'add':

            if len(request.POST['teacher_selected'].strip()) == 0:
                error = 'Error - Please click on the name when it drops down.'

            elif (request.POST['teacher_selected'] == str(request.user.id)):
                error = 'Error - You cannot select yourself as a coteacher!'
            elif request.POST['teacher_selected'] in txtTeachers.split(','):
                error = 'Error - You already added this teacher as a coteacher!'

            if error:
                return render_to_response(
                    self.baseDir() + 'coteachers.html', request, {
                        'class': cls,
                        'ajax': ajax,
                        'txtTeachers': txtTeachers,
                        'coteachers': coteachers,
                        'error': error,
                        'conflicts': []
                    })

            # add schedule conflict checking here...
            teacher = ESPUser.objects.get(id=request.POST['teacher_selected'])

            if cls.conflicts(teacher):
                conflictingusers.append(teacher.first_name + ' ' +
                                        teacher.last_name)
            else:
                coteachers.append(teacher)
                txtTeachers = ",".join(
                    [str(coteacher.id) for coteacher in coteachers])

        elif op == 'del':
            ids = request.POST.getlist('delete_coteachers')
            newcoteachers = []
            for coteacher in coteachers:
                if str(coteacher.id) not in ids:
                    newcoteachers.append(coteacher)

            coteachers = newcoteachers
            txtTeachers = ",".join(
                [str(coteacher.id) for coteacher in coteachers])

        elif op == 'save':
            old_coteachers_set = set(cls.get_teachers())
            new_coteachers_set = set(coteachers)

            to_be_added = new_coteachers_set - old_coteachers_set
            to_be_deleted = old_coteachers_set - new_coteachers_set

            # don't delete the current user
            if request.user in to_be_deleted:
                to_be_deleted.remove(request.user)

            for teacher in to_be_added:
                if cls.conflicts(teacher):
                    conflictingusers.append(teacher.first_name + ' ' +
                                            teacher.last_name)

            if len(conflictingusers) == 0:
                # remove some old coteachers
                for teacher in to_be_deleted:
                    cls.removeTeacher(teacher)

                # add bits for all new coteachers
                ccc = ClassCreationController(self.program)
                for teacher in to_be_added:
                    ccc.associate_teacher_with_class(cls, teacher)
                ccc.send_class_mail_to_directors(cls)
                return self.goToCore(tl)

        return render_to_response(
            self.baseDir() + 'coteachers.html', request, {
                'class': cls,
                'ajax': ajax,
                'txtTeachers': txtTeachers,
                'coteachers': coteachers,
                'conflicts': conflictingusers
            })
示例#2
0
    def coteachers(self, request, tl, one, two, module, extra, prog):
        from esp.users.models import ESPUser 
        
        #   Allow submitting class ID via either GET or POST.
        if request.GET.has_key('clsid'):
            clsid = request.GET['clsid']
        elif request.POST.has_key('clsid'):
            clsid = request.POST['clsid']
        else:
            return self.goToCore(tl) # just fails.

        if extra == 'nojs':
            ajax = False
        else:
            ajax = True
            
        classes = ClassSubject.objects.filter(id = clsid)
        if len(classes) != 1 or not request.user.canEdit(classes[0]):
            return render_to_response(self.baseDir()+'cannoteditclass.html', request, (prog, tl),{})

        cls = classes[0]

        # set txtTeachers and coteachers....
        if not request.POST.has_key('coteachers'):
            coteachers = cls.teachers()
            coteachers = [ ESPUser(user) for user in coteachers ]
            
            txtTeachers = ",".join([str(user.id) for user in coteachers ])
            
        else:
            txtTeachers = request.POST['coteachers']
            coteachers = txtTeachers.split(',')
            coteachers = [ x for x in coteachers if x != '' ]
            coteachers = [ ESPUser(User.objects.get(id=userid))
                           for userid in coteachers                ]

        op = ''
        if request.POST.has_key('op'):
            op = request.POST['op']

        conflictingusers = []
        error = False
        
        if op == 'add':

            if len(request.POST['teacher_selected'].strip()) == 0:
                error = 'Error - Please click on the name when it drops down.'

            elif request.POST['teacher_selected'] in txtTeachers.split(','):
                error = 'Error - You already added this teacher as a coteacher!'

            if error:
                return render_to_response(self.baseDir()+'coteachers.html', request, (prog, tl),{'class':cls,
                                                                                                 'ajax':ajax,
                                                                                                 'txtTeachers': txtTeachers,
                                                                                                 'coteachers':  coteachers,
                                                                                                 'error': error})
            
            # add schedule conflict checking here...
            teacher = ESPUser.objects.get(id = request.POST['teacher_selected'])

            if cls.conflicts(teacher):
                conflictingusers.append(teacher.first_name+' '+teacher.last_name)
            else:    
                coteachers.append(teacher)
                txtTeachers = ",".join([str(coteacher.id) for coteacher in coteachers ])
            
        elif op == 'del':
            ids = request.POST.getlist('delete_coteachers')
            newcoteachers = []
            for coteacher in coteachers:
                if str(coteacher.id) not in ids:
                    newcoteachers.append(coteacher)

            coteachers = newcoteachers
            txtTeachers = ",".join([str(coteacher.id) for coteacher in coteachers ])
                         

        elif op == 'save':
            #            if
            for teacher in coteachers:
                if cls.conflicts(teacher):
                    conflictingusers.append(teacher.first_name+' '+teacher.last_name)
            if len(conflictingusers) == 0:
                for teacher in cls.teachers():
                    cls.removeTeacher(teacher)
                    cls.removeAdmin(teacher)

                # add bits for all new (and old) coteachers
                ccc = ClassCreationController(self.program)
                for teacher in coteachers:
                    ccc.associate_teacher_with_class(cls, teacher)
                ccc.send_class_mail_to_directors(cls)
                return self.goToCore(tl)


        
        return render_to_response(self.baseDir()+'coteachers.html', request, (prog, tl),{'class':cls,
                                                                                         'ajax':ajax,
                                                                                         'txtTeachers': txtTeachers,
                                                                                         'coteachers':  coteachers,
                                                                                         'conflicts':   conflictingusers})
class TeacherCheckinModuleTest(ProgramFrameworkTest):

    def setUp(self, *args, **kwargs):
        super(TeacherCheckinModuleTest, self).setUp(*args, **kwargs)
        self.add_user_profiles()
        self.schedule_randomly() # only scheduled classes used in module
        self.ccc      = ClassCreationController(self.program)
        pm            = ProgramModule.objects.get(handler='TeacherCheckinModule')
        self.module   = ProgramModuleObj.getFromProgModule(self.program, pm)
        self.now      = self.settings['start_time']
        self.past     = datetime.datetime(1970, 1, 1)
        self.future   = datetime.datetime.max
        self.admin    = self.admins[0]
        self.teacher  = self.teachers[0]
        self.cls      = self.teacher.getTaughtClasses()[0]
        self.event    = 'teacher_checked_in'
        self.teacher2 = ESPUser.objects.create(username='******')
        self.teacher2.makeRole("Teacher")

    def tearDown(self):
        Record.objects.filter(program=self.program, event=self.event).delete()
        super(TeacherCheckinModuleTest, self).tearDown()

    def addCoteacher(self, cls, coteacher):
        self.ccc.associate_teacher_with_class(cls, coteacher)

    # Aliases so full set of args don't need to be typed each time.
    # 'when' defaults to self.now (the datetime of the program), and
    # 'teacher' defaults to self.teacher.

    def isCheckedIn(self, when=None, teacher=None):
        if when is None:
            when = self.now
        if teacher is None:
            teacher = self.teacher
        return Record.user_completed(teacher, self.event, self.program,
                                     when, only_today=True)

    def checkIn(self, when=None, teacher=None):
        if when is None:
            when = self.now
        if teacher is None:
            teacher = self.teacher
        return self.module.checkIn(teacher, self.program, when)

    def undoCheckIn(self, when=None, teacher=None):
        if when is None:
            when = self.now
        if teacher is None:
            teacher = self.teacher
        return self.module.undoCheckIn(teacher, self.program, when)

    # End aliases.

    def test_checkIn(self):
        """Run tests for checkIn() and undoCheckIn()."""

        # Test that calling checkIn() works, and
        # that calling it again does nothing.
        self.assertFalse(self.isCheckedIn())
        self.assertIn('is checked in until', self.checkIn())
        self.assertTrue(self.isCheckedIn())
        self.assertIn('has already been checked in until', self.checkIn())
        self.assertTrue(self.isCheckedIn())

        # Test that checking in the teacher in the present has no effect on
        # check-in status in the past or future, and that checking in the
        # teacher in the future has no effect on check-in status in the
        # present or past.
        self.assertFalse(self.isCheckedIn(self.past))
        self.assertFalse(self.isCheckedIn(self.future))
        self.assertIn('is checked in until', self.checkIn(self.future))
        self.assertTrue(self.isCheckedIn())
        self.assertTrue(self.isCheckedIn(self.future))
        self.assertFalse(self.isCheckedIn(self.past))

        # Test that undoing check-in in the future has no effect on check-in
        # status in the present or past.
        self.assertIn('is no longer checked in.', self.undoCheckIn(self.future))
        self.assertFalse(self.isCheckedIn(self.future))
        self.assertTrue(self.isCheckedIn())
        self.assertFalse(self.isCheckedIn(self.past))

        # Test that calling undoCheckIn() works, and
        # that calling it again does nothing.
        self.assertIn('is no longer checked in.', self.undoCheckIn())
        self.assertFalse(self.isCheckedIn())
        self.assertIn('was not checked in for', self.undoCheckIn())
        self.assertFalse(self.isCheckedIn())

        # Test that you can't successfully call checkIn() or undoCheckIn()
        # for a user who is not teaching a class for the program.
        self.assertIn('is not a teacher for',
                      self.checkIn(teacher=self.teacher2))
        self.assertIn('was not checked in for',
                      self.undoCheckIn(teacher=self.teacher2))

    def test_phone_numbers_on_checkin_page(self):
        self.assertTrue(self.client.login(username=self.admin.username, password='******'), "Couldn't log in as admin %s" % self.admin.username)
        response = self.client.get(u'%smissingteachers' % self.program.get_onsite_url())
        phone = self.teacher.getLastProfile().contact_user.phone_cell
        self.assertIn(phone, response.content.decode('utf-8'))
示例#4
0
class TeacherCheckinModuleTest(ProgramFrameworkTest):
    def setUp(self, *args, **kwargs):
        super(TeacherCheckinModuleTest, self).setUp(*args, **kwargs)
        self.add_user_profiles()
        self.schedule_randomly()  # only scheduled classes used in module
        self.ccc = ClassCreationController(self.program)
        pm = ProgramModule.objects.get(handler='TeacherCheckinModule')
        self.module = ProgramModuleObj.getFromProgModule(self.program, pm)
        self.now = self.settings['start_time']
        self.past = datetime.datetime(1970, 1, 1)
        self.future = datetime.datetime.max
        self.admin = self.admins[0]
        self.teacher = self.teachers[0]
        self.cls = self.teacher.getTaughtClasses()[0]
        self.event = 'teacher_checked_in'
        self.teacher2 = ESPUser.objects.create(username='******')
        self.teacher2.makeRole("Teacher")

    def tearDown(self):
        Record.objects.filter(program=self.program, event=self.event).delete()
        super(TeacherCheckinModuleTest, self).tearDown()

    def addCoteacher(self, cls, coteacher):
        self.ccc.associate_teacher_with_class(cls, coteacher)

    # Aliases so full set of args don't need to be typed each time.
    # 'when' defaults to self.now (the datetime of the program), and
    # 'teacher' defaults to self.teacher.

    def isCheckedIn(self, when=None, teacher=None):
        if when is None:
            when = self.now
        if teacher is None:
            teacher = self.teacher
        return Record.user_completed(teacher,
                                     self.event,
                                     self.program,
                                     when,
                                     only_today=True)

    def checkIn(self, when=None, teacher=None):
        if when is None:
            when = self.now
        if teacher is None:
            teacher = self.teacher
        return self.module.checkIn(teacher, self.program, when)

    def undoCheckIn(self, when=None, teacher=None):
        if when is None:
            when = self.now
        if teacher is None:
            teacher = self.teacher
        return self.module.undoCheckIn(teacher, self.program, when)

    # End aliases.

    def test_checkIn(self):
        """Run tests for checkIn() and undoCheckIn()."""

        # Test that calling checkIn() works, and
        # that calling it again does nothing.
        self.assertFalse(self.isCheckedIn())
        self.assertIn('is checked in until', self.checkIn())
        self.assertTrue(self.isCheckedIn())
        self.assertIn('has already been checked in until', self.checkIn())
        self.assertTrue(self.isCheckedIn())

        # Test that checking in the teacher in the present has no effect on
        # check-in status in the past or future, and that checking in the
        # teacher in the future has no effect on check-in status in the
        # present or past.
        self.assertFalse(self.isCheckedIn(self.past))
        self.assertFalse(self.isCheckedIn(self.future))
        self.assertIn('is checked in until', self.checkIn(self.future))
        self.assertTrue(self.isCheckedIn())
        self.assertTrue(self.isCheckedIn(self.future))
        self.assertFalse(self.isCheckedIn(self.past))

        # Test that undoing check-in in the future has no effect on check-in
        # status in the present or past.
        self.assertIn('is no longer checked in.',
                      self.undoCheckIn(self.future))
        self.assertFalse(self.isCheckedIn(self.future))
        self.assertTrue(self.isCheckedIn())
        self.assertFalse(self.isCheckedIn(self.past))

        # Test that calling undoCheckIn() works, and
        # that calling it again does nothing.
        self.assertIn('is no longer checked in.', self.undoCheckIn())
        self.assertFalse(self.isCheckedIn())
        self.assertIn('was not checked in for', self.undoCheckIn())
        self.assertFalse(self.isCheckedIn())

        # Test that you can't successfully call checkIn() or undoCheckIn()
        # for a user who is not teaching a class for the program.
        self.assertIn('is not a teacher for',
                      self.checkIn(teacher=self.teacher2))
        self.assertIn('was not checked in for',
                      self.undoCheckIn(teacher=self.teacher2))

    def test_phone_numbers_on_checkin_page(self):
        self.assertTrue(
            self.client.login(username=self.admin.username,
                              password='******'),
            "Couldn't log in as admin %s" % self.admin.username)
        response = self.client.get(u'%smissingteachers' %
                                   self.program.get_onsite_url())
        phone = self.teacher.getLastProfile().contact_user.phone_cell
        self.assertIn(phone, response.content.decode('utf-8'))
    def coteachers(self, request, tl, one, two, module, extra, prog):
        from esp.users.models import ESPUser

        #   Allow submitting class ID via either GET or POST.
        if 'clsid' in request.GET:
            clsid = request.GET['clsid']
        elif 'clsid' in request.POST:
            clsid = request.POST['clsid']
        else:
            return self.goToCore(tl) # just fails.

        if extra == 'nojs':
            ajax = False
        else:
            ajax = True

        classes = ClassSubject.objects.filter(id = clsid)
        if len(classes) != 1 or not request.user.canEdit(classes[0]):
            return render_to_response(self.baseDir()+'cannoteditclass.html', request, {})

        cls = classes[0]

        # set txtTeachers and coteachers....
        if not 'coteachers' in request.POST:
            coteachers = cls.get_teachers()
            coteachers = [ user for user in coteachers
                           if user.id != request.user.id           ]

            txtTeachers = ",".join([str(user.id) for user in coteachers ])

        else:
            txtTeachers = request.POST['coteachers']
            coteachers = txtTeachers.split(',')
            coteachers = [ x for x in coteachers if x != '' ]
            coteachers = [ ESPUser.objects.get(id=userid)
                           for userid in coteachers                ]

        op = ''
        if 'op' in request.POST:
            op = request.POST['op']

        conflictingusers = []
        error = False

        if op == 'add':

            if len(request.POST['teacher_selected'].strip()) == 0:
                error = 'Error - Please click on the name when it drops down.'

            elif request.POST['teacher_selected'] in txtTeachers.split(','):
                error = 'Error - You already added this teacher as a coteacher!'

            if error:
                return render_to_response(self.baseDir()+'coteachers.html', request,
                                          {'class': cls,
                                           'ajax': ajax,
                                           'txtTeachers': txtTeachers,
                                           'coteachers': coteachers,
                                           'error': error})

            # add schedule conflict checking here...
            teacher = ESPUser.objects.get(id = request.POST['teacher_selected'])

            if cls.conflicts(teacher):
                conflictingusers.append(teacher.first_name+' '+teacher.last_name)
            else:
                coteachers.append(teacher)
                txtTeachers = ",".join([str(coteacher.id) for coteacher in coteachers ])

        elif op == 'del':
            ids = request.POST.getlist('delete_coteachers')
            newcoteachers = []
            for coteacher in coteachers:
                if str(coteacher.id) not in ids:
                    newcoteachers.append(coteacher)

            coteachers = newcoteachers
            txtTeachers = ",".join([str(coteacher.id) for coteacher in coteachers ])


        elif op == 'save':
            #            if
            for teacher in coteachers:
                if cls.conflicts(teacher):
                    conflictingusers.append(teacher.first_name+' '+teacher.last_name)
            if len(conflictingusers) == 0:
                for teacher in cls.get_teachers():
                    cls.removeTeacher(teacher)

                # add bits for all new (and old) coteachers
                ccc = ClassCreationController(self.program)
                for teacher in coteachers:
                    ccc.associate_teacher_with_class(cls, teacher)
                ccc.send_class_mail_to_directors(cls)
                return self.goToCore(tl)



        return render_to_response(self.baseDir()+'coteachers.html', request,
                                  {'class': cls,
                                   'ajax': ajax,
                                   'txtTeachers': txtTeachers,
                                   'coteachers': coteachers,
                                   'conflicts': conflictingusers})