Ignore:
Timestamp:
9 Feb 2018, 09:17:58 (7 years ago)
Author:
Henrik Bettermann
Message:

Display applicant id and error messages in flash message box if student creation has failed.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
4 edited

Legend:

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

    r14948 r14949  
    2929from zope.catalog.interfaces import ICatalog
    3030from zope.i18n import translate
     31from zope.security import checkPermission
    3132from hurry.workflow.interfaces import (
    3233    IWorkflowInfo, IWorkflowState, InvalidTransitionError)
     
    430431    @action(_('Create students from selected'))
    431432    def createStudents(self, **data):
     433        if not checkPermission('waeup.createStudents', self.context):
     434            self.flash(
     435                _('You don\'t have permission to create student records.'),
     436                type='warning')
     437            self.redirect(self.url(self.context, '@@manage')+'#tab2')
     438            return
    432439        form = self.request.form
    433440        if 'val_id' in form:
     
    697704        results = list(cat.searchResults(state=(ADMITTED, ADMITTED)))
    698705        created = []
     706        failed = []
    699707        container_only = False
    700708        applicants_root = grok.getSite()['applicants']
     
    708716                created.append(result.applicant_id)
    709717            else:
     718                failed.append('%s (%s)' % (result.applicant_id, msg))
    710719                ob_class = self.__implemented__.__name__.replace(
    711720                    'waeup.kofa.','')
     
    716725            self.flash(_('${a} students successfully created.',
    717726                mapping = {'a': len(created)}))
    718         else:
    719             self.flash(_('No student could be created.'), type='warning')
     727        if len(failed):
     728            self.flash(_('Student creation failed: ${a}',
     729                mapping = {'a':', '.join(failed)}), type='danger')
     730        if not len(created) and not len(failed):
     731            self.flash(_('No record found.'), type='warning')
    720732        self.redirect(self.url(self.context))
    721733        return
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py

    r14934 r14949  
    160160        self.prepare_applicant()
    161161        self.browser.open(self.container_path + '/createallstudents')
    162         self.assertTrue('No student could be created' in self.browser.contents)
     162        self.assertTrue('No record found' in self.browser.contents)
    163163        IWorkflowState(self.applicant).setState('admitted')
    164164        notify(grok.ObjectModifiedEvent(self.applicant))
    165165        self.browser.open(self.container_path + '/createallstudents')
    166         self.assertTrue('No student could be created' in self.browser.contents)
     166        self.assertTrue('No course admitted provided' in self.browser.contents)
    167167        logcontent = open(logfile).read()
    168168        self.assertTrue('No course admitted provided' in logcontent)
     
    173173        self.applicant.date_of_birth = None
    174174        self.browser.open(self.container_path + '/createallstudents')
    175         self.assertTrue('No student could be created' in self.browser.contents)
     175        self.assertTrue('RequiredMissing: date_of_birth' in self.browser.contents)
    176176        logcontent = open(logfile).read()
    177177        self.assertTrue('RequiredMissing: date_of_birth' in logcontent)
     
    194194        notify(grok.ObjectModifiedEvent(self.applicant))
    195195        self.browser.open(self.root_path + '/createallstudents')
    196         self.assertTrue('No student could be created' in self.browser.contents)
     196        self.assertTrue('No course admitted provided' in self.browser.contents)
    197197        logcontent = open(logfile).read()
    198198        self.assertTrue('No course admitted provided' in logcontent)
     
    238238        self.assertTrue('No student could be created.' in self.browser.contents)
    239239        self.browser.open(self.container_path + '/createallstudents')
    240         self.assertTrue('No student could be created' in self.browser.contents)
    241         logfile = os.path.join(self.app['datacenter'].storage, 'logs', 'applicants.log')
    242         logcontent = open(logfile).read()
    243         self.assertTrue('IOError: Application Slip could not be created.' in logcontent)
     240        self.assertTrue(
     241            'IOError: Application Slip could not be created.'
     242            in self.browser.contents)
     243        logfile = os.path.join(
     244            self.app['datacenter'].storage, 'logs', 'applicants.log')
     245        logcontent = open(logfile).read()
     246        self.assertTrue(
     247            'IOError: Application Slip could not be created.' in logcontent)
    244248
    245249    def disabled_test_delay(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r14366 r14949  
    536536        self.assertEqual(self.applicantscontainer.counts[1], 0)
    537537        return
     538
     539    def init_officer(self):
     540        # Create application officer
     541        self.app['users'].addUser('mrappl', 'mrapplsecret')
     542        self.app['users']['mrappl'].email = 'mrappl@foo.ng'
     543        self.app['users']['mrappl'].title = 'Carlo Pitter'
     544        prmglobal = IPrincipalRoleManager(self.app)
     545        prmglobal.assignRoleToPrincipal('waeup.ApplicationsManager', 'mrappl')
     546        # Login as officer
     547        self.browser.open(self.login_path)
     548        self.browser.getControl(name="form.login").value = 'mrappl'
     549        self.browser.getControl(name="form.password").value = 'mrapplsecret'
     550        self.browser.getControl("Login").click()
     551
     552    def test_student_creation_permission(self):
     553        self.init_officer()
     554        self.browser.open(self.container_path + '/manage')
     555        self.browser.getControl("Create students").click()
     556        self.assertTrue('You don\'t have permission to create student records'
     557            in self.browser.contents)
     558        prmglobal = IPrincipalRoleManager(self.app)
     559        prmglobal.assignRoleToPrincipal('waeup.StudentsCreator', 'mrappl')
     560        self.browser.getControl("Create students").click()
     561        self.assertTrue('No applicant selected' in self.browser.contents)
     562
    538563
    539564class ApplicantUITests(ApplicantsFullSetup):
  • main/waeup.kofa/trunk/src/waeup/kofa/permissions.py

    r14948 r14949  
    566566                     'waeup.clearStudentFinancially',  # not used in base pkg
    567567                     'waeup.uploadStudentFile', 'waeup.showStudents',
    568                      'waeup.clearAllStudents', 'waeup.createStudents',
     568                     'waeup.clearAllStudents',
     569                     'waeup.createStudents',
    569570                     'waeup.editScores',
    570571                     'waeup.triggerTransition',
     
    614615        'waeup.clearStudent', 'waeup.payStudent',
    615616        'waeup.uploadStudentFile', 'waeup.showStudents',
    616         'waeup.clearAllStudents', 'waeup.createStudents',
     617        'waeup.clearAllStudents',
     618        # 'waeup.createStudents',
    617619        'waeup.editScores',
    618620        # 'waeup.triggerTransition',
Note: See TracChangeset for help on using the changeset viewer.