Changeset 11862


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
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r11826 r11862  
    441.3dev (unreleased)
    55===================
     6
     7* Add permission, page and button to mass-clear all students in a department.
    68
    79* Hide export download button 24 hours after file generation.
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/viewlets.py

    r11254 r11862  
    476476    grok.order(3)
    477477
     478class ClearDepartmentStudentsActionButton(ManageActionButton):
     479    """ 'Clear all students' button for departments.
     480    """
     481    grok.context(IDepartment)
     482    grok.view(DepartmentPage)
     483    grok.name('cleardepartmentstudents')
     484    grok.require('waeup.clearAllStudents')
     485    icon = 'actionicon_accept.png'
     486    text = _('Clear all students')
     487    target = 'clearallstudents'
     488    grok.order(4)
     489
     490    @property
     491    def onclick(self):
     492        return "return window.confirm(%s);" % _(
     493            "'All students, who requested clearance in this department, will be cleared. Are you sure?'")
     494
    478495class ManageCourseActionButton(ManageActionButton):
    479496    """ 'Edit settings' button for courses.
  • main/waeup.kofa/trunk/src/waeup/kofa/permissions.py

    r11673 r11862  
    5959    grok.name('waeup.showStudents')
    6060
     61class ClearAllStudents(grok.Permission):
     62    grok.name('waeup.clearAllStudents')
     63
    6164class EditScores(grok.Permission):
    6265    grok.name('waeup.editScores')
     
    128131    grok.permissions('waeup.showStudents',
    129132                     'waeup.viewAcademics',
    130                      'waeup.exportData')
     133                     'waeup.exportData',
     134                     'waeup.clearAllStudents')
    131135
    132136class LocalStudentsManager(grok.Role):
     
    158162    grok.permissions('waeup.showStudents',
    159163                     'waeup.viewAcademics',
    160                      'waeup.exportData')
     164                     'waeup.exportData',
     165                     'waeup.clearAllStudents')
    161166
    162167class PGClearanceOfficer(grok.Role):
     
    168173    grok.permissions('waeup.showStudents',
    169174                     'waeup.viewAcademics',
    170                      'waeup.exportData')
     175                     'waeup.exportData',
     176                     'waeup.clearAllStudents')
    171177
    172178class CourseAdviser100(grok.Role):
     
    336342                     'waeup.clearStudent', 'waeup.payStudent',
    337343                     'waeup.uploadStudentFile', 'waeup.showStudents',
     344                     'waeup.clearAllStudents',
    338345                     'waeup.editScores',
    339346                     'waeup.triggerTransition',
     
    369376                     'waeup.clearStudent', 'waeup.payStudent',
    370377                     'waeup.uploadStudentFile', 'waeup.showStudents',
     378                     'waeup.clearAllStudents',
    371379                     'waeup.editScores',
    372380                     #'waeup.triggerTransition',
  • 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.