Ignore:
Timestamp:
21 Oct 2014, 07:07:04 (10 years ago)
Author:
Henrik Bettermann
Message:

Add permission, page and button to mass-clear all students in a department.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r11772 r11862  
    30043004        return list(set(hitlist))
    30053005
     3006class ClearAllStudentsInDepartmentPage(UtilityView, grok.View):
     3007    """ Clear all students of a department in state 'clearance requested'.
     3008    """
     3009    grok.context(IDepartment)
     3010    grok.name('clearallstudents')
     3011    grok.require('waeup.clearAllStudents')
     3012
     3013    def update(self):
     3014        cat = queryUtility(ICatalog, name='students_catalog')
     3015        students = cat.searchResults(
     3016            depcode=(self.context.code, self.context.code),
     3017            state=(REQUESTED, REQUESTED)
     3018            )
     3019        num = 0
     3020        for student in students:
     3021            if getUtility(IStudentsUtils).clearance_disabled_message(student):
     3022                continue
     3023            IWorkflowInfo(student).fireTransition('clear')
     3024            num += 1
     3025        self.flash(_('%d students have been cleared.' % num))
     3026        self.redirect(self.url(self.context))
     3027        return
     3028
     3029    def render(self):
     3030        return
     3031
     3032
    30063033class EditScoresPage(KofaPage):
    30073034    """Page that filters and lists students.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r11774 r11862  
    13841384        return
    13851385
    1386     def test_handle_clearance_by_co(self):
     1386    def init_clearance_officer(self):
    13871387        # Create clearance officer
    13881388        self.app['users'].addUser('mrclear', 'mrclearsecret')
     
    13941394        #prmglobal.assignRoleToPrincipal('waeup.StudentsOfficer', 'mrclear')
    13951395        # Assign local ClearanceOfficer role
    1396         department = self.app['faculties']['fac1']['dep1']
    1397         prmlocal = IPrincipalRoleManager(department)
     1396        self.department = self.app['faculties']['fac1']['dep1']
     1397        prmlocal = IPrincipalRoleManager(self.department)
    13981398        prmlocal.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'mrclear')
    13991399        IWorkflowState(self.student).setState('clearance started')
     1400        # Add another student for testing
     1401        other_student = Student()
     1402        other_student.firstname = u'Dep2'
     1403        other_student.lastname = u'Student'
     1404        self.app['students'].addStudent(other_student)
     1405        self.other_student_path = (
     1406            'http://localhost/app/students/%s' % other_student.student_id)
    14001407        # Login as clearance officer
    14011408        self.browser.open(self.login_path)
     
    14031410        self.browser.getControl(name="form.password").value = 'mrclearsecret'
    14041411        self.browser.getControl("Login").click()
     1412
     1413    def test_handle_clearance_by_co(self):
     1414        self.init_clearance_officer()
    14051415        self.assertMatches('...You logged in...', self.browser.contents)
    14061416        # CO is landing on index page
     
    14191429        # has changed
    14201430        notify(LocalRoleSetEvent(
    1421             department, 'waeup.local.ClearanceOfficer', 'mrclear', granted=True))
     1431            self.department, 'waeup.local.ClearanceOfficer', 'mrclear', granted=True))
    14221432        self.browser.open('http://localhost/app/users/mrclear/my_roles')
    14231433        self.assertTrue('Clearance Officer' in self.browser.contents)
     
    14301440        self.assertEqual(self.browser.url, self.clearance_path)
    14311441        # ... but not other students
    1432         other_student = Student()
    1433         other_student.firstname = u'Dep2'
    1434         other_student.lastname = u'Student'
    1435         self.app['students'].addStudent(other_student)
    1436         other_student_path = (
    1437             'http://localhost/app/students/%s' % other_student.student_id)
    14381442        self.assertRaises(
    1439             Unauthorized, self.browser.open, other_student_path)
     1443            Unauthorized, self.browser.open, self.other_student_path)
    14401444        # Clearance is disabled for this session
    14411445        self.browser.open(self.clearance_path)
     
    15361540        IWorkflowInfo(self.student).fireTransition('clear')
    15371541        self.assertEqual(self.student.officer_comment, None)
     1542        return
     1543
     1544    def test_handle_mass_clearance_by_co(self):
     1545        self.init_clearance_officer()
     1546        # Additional setups according to test above
     1547        notify(LocalRoleSetEvent(
     1548            self.department, 'waeup.local.ClearanceOfficer', 'mrclear', granted=True))
     1549        self.app['configuration']['2004'].clearance_enabled = True
     1550        IWorkflowState(self.student).setState('clearance requested')
     1551        # Update the catalog
     1552        notify(grok.ObjectModifiedEvent(self.student))
     1553        # The CO can go to the department and clear all students in department
     1554        self.browser.open('http://localhost/app/faculties/fac1/dep1')
     1555        self.browser.getLink("Clear all students").click()
     1556        self.assertTrue('1 students have been cleared' in self.browser.contents)
     1557        self.browser.open(self.history_path)
     1558        self.assertTrue('Cleared by Carlo Pitter' in self.browser.contents)
     1559        logfile = os.path.join(
     1560            self.app['datacenter'].storage, 'logs', 'students.log')
     1561        logcontent = open(logfile).read()
     1562        self.assertTrue(
     1563            'INFO - mrclear - K1000000 - Cleared' in logcontent)
     1564        self.browser.open('http://localhost/app/faculties/fac1/dep1')
     1565        self.browser.getLink("Clear all students").click()
     1566        self.assertTrue('0 students have been cleared' in self.browser.contents)
     1567        return
    15381568
    15391569    def test_handle_courses_by_ca(self):
Note: See TracChangeset for help on using the changeset viewer.