Ignore:
Timestamp:
6 Jun 2012, 09:17:37 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement CreateAllStudentsPage? which creates students from all admitted students in a container.

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

Legend:

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

    r8629 r8636  
    3636    )
    3737from waeup.kofa.applicants.applicant import search
    38 from waeup.kofa.applicants.workflow import INITIALIZED, STARTED, PAID, SUBMITTED
     38from waeup.kofa.applicants.workflow import (
     39    INITIALIZED, STARTED, PAID, SUBMITTED, ADMITTED)
    3940from waeup.kofa.browser import (
    4041    KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage,
     
    545546
    546547class CreateStudentPage(UtilityView, grok.View):
    547     """Create a student object from applicatnt data
    548     and copy applicant object.
     548    """Create a student object from applicant data.
    549549    """
    550550    grok.context(IApplicant)
     
    556556        self.flash(msg)
    557557        self.redirect(self.url(self.context))
     558        return
     559
     560    def render(self):
     561        return
     562
     563class CreateAllStudentsPage(UtilityView, grok.View):
     564    """Create all student objects from applicant data
     565    in a container.
     566
     567    This is a hidden page, no link or button will
     568    be provided and only PortalManagers can do this.
     569    """
     570    grok.context(IApplicantsContainer)
     571    grok.name('createallstudents')
     572    grok.require('waeup.managePortal')
     573
     574    def update(self):
     575        cat = getUtility(ICatalog, name='applicants_catalog')
     576        results = list(cat.searchResults(state=(ADMITTED, ADMITTED)))
     577        created = []
     578        for result in results:
     579            if not self.context.has_key(result.application_number):
     580                continue
     581            success, msg = result.createStudent(view=self)
     582            if success:
     583                created.append(result.applicant_id)
     584            else:
     585                ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
     586                self.context.__parent__.logger_info(
     587                    ob_class,result.applicant_id,msg)
     588        if len(created):
     589            self.flash(_('${a} students successfully created.',
     590                mapping = {'a': len(created)}))
     591        else:
     592            self.flash(_('No student could be created.'))
     593        self.redirect(self.url(self.context, u'@@manage')+'?tab2')
    558594        return
    559595
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py

    r8487 r8636  
    2020"""
    2121import os
     22import grok
    2223from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
     24from zope.event import notify
    2325from zope.component import getUtility
    2426from zope.i18n import translate
     
    3537        return
    3638
    37     def test_copier(self):
     39    def prepare_applicant(self):
    3840        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    3941        self.browser.open(self.manage_path)
     
    4749        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
    4850        self.browser.getControl("Save").click() # submit form
     51        return
     52
     53    def test_copier(self):
     54        self.prepare_applicant()
    4955        storage = getUtility(IExtFileStore)
    5056        file_id = IFileStoreNameChooser(self.applicant).chooseName()
     
    100106
    101107    def test_batch_copying(self):
    102         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    103         self.browser.open(self.manage_path)
    104         self.fill_correct_values()
    105         self.browser.getControl("Save").click()
    106         # Upload a passport picture
    107         ctrl = self.browser.getControl(name='form.passport')
    108         file_obj = open(
    109             os.path.join(os.path.dirname(__file__), 'test_image.jpg'),'rb')
    110         file_ctrl = ctrl.mech_control
    111         file_ctrl.add_file(file_obj, filename='my_photo.jpg')
    112         self.browser.getControl("Save").click() # submit form
     108        self.prepare_applicant()
    113109        IWorkflowState(self.applicant).setState('admitted')
    114110        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
     
    120116        ctrl.getControl(value=self.applicant.application_number).selected = True
    121117        self.browser.getControl("Create students from selected", index=0).click()
     118        self.assertTrue('1 students successfully created' in self.browser.contents)
     119
     120    def test_hidden_batch_copying(self):
     121        logfile = os.path.join(
     122            self.app['datacenter'].storage, 'logs', 'applicants.log')
     123        self.prepare_applicant()
     124        self.browser.open(self.container_path + '/createallstudents')
     125        self.assertTrue('No student could be created' in self.browser.contents)
     126        IWorkflowState(self.applicant).setState('admitted')
     127        notify(grok.ObjectModifiedEvent(self.applicant))
     128        self.browser.open(self.container_path + '/createallstudents')
     129        self.assertTrue('No student could be created' in self.browser.contents)
     130        logcontent = open(logfile).read()
     131        self.assertTrue('No course admitted provided' in logcontent)
     132        self.browser.open(self.manage_path)
     133        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
     134        self.browser.getControl("Save").click()
     135        # date_of_birth is not required for applicants but for students
     136        self.applicant.date_of_birth = None
     137        self.browser.open(self.container_path + '/createallstudents')
     138        self.assertTrue('No student could be created' in self.browser.contents)
     139        logcontent = open(logfile).read()
     140        self.assertTrue('RequiredMissing: date_of_birth' in logcontent)
     141        self.browser.open(self.manage_path)
     142        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
     143        self.browser.getControl("Save").click()
     144        self.browser.open(self.container_path + '/createallstudents')
    122145        self.assertTrue('1 students successfully created' in self.browser.contents)
    123146
Note: See TracChangeset for help on using the changeset viewer.