Changeset 8314


Ignore:
Timestamp:
30 Apr 2012, 06:00:27 (13 years ago)
Author:
Henrik Bettermann
Message:

Add method and helpers to mass-create students from applicants.

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

Legend:

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

    r8286 r8314  
    4242from waeup.kofa.browser.interfaces import ICaptchaManager
    4343from waeup.kofa.browser.breadcrumbs import Breadcrumb
     44from waeup.kofa.browser.resources import toggleall
    4445from waeup.kofa.browser.layout import (
    4546    NullValidator, jsaction, action, UtilityView)
     
    253254    form_fields = grok.AutoFields(IApplicantsContainer).omit('title')
    254255    taboneactions = [_('Save'),_('Cancel')]
    255     tabtwoactions = [_('Add applicant'), _('Remove selected'),_('Cancel')]
     256    tabtwoactions = [_('Add applicant'), _('Remove selected'),_('Cancel'),
     257        _('Create students from selected')]
    256258    tabthreeactions1 = [_('Remove selected local roles')]
    257259    tabthreeactions2 = [_('Add local role')]
     
    268270        datepicker.need() # Enable jQuery datepicker in date fields.
    269271        tabs.need()
     272        toggleall.need()
    270273        self.tab1 = self.tab2 = self.tab3 = ''
    271274        qs = self.request.get('QUERY_STRING', '')
     
    334337        return
    335338
     339    @action(_('Create students from selected'))
     340    def createStudents(self, **data):
     341        form = self.request.form
     342        if form.has_key('val_id'):
     343            child_id = form['val_id']
     344        else:
     345            self.flash(_('No applicant selected!'))
     346            self.redirect(self.url(self.context, '@@manage')+'?tab2')
     347            return
     348        if not isinstance(child_id, list):
     349            child_id = [child_id]
     350        created = []
     351        for id in child_id:
     352            success, msg = self.context[id].createStudent(view=self)
     353            if success:
     354                created.append(id)
     355        if len(created):
     356            self.flash(_('${a} students successfully created.',
     357                mapping = {'a': len(created)}))
     358        else:
     359            self.flash(_('No student could be created.'))
     360        self.redirect(self.url(self.context, u'@@manage')+'?tab2')
     361        return
     362
    336363    @action(_('Cancel'), validator=NullValidator)
    337364    def cancel(self, **data):
     
    434461
    435462    def update(self):
    436         msg = self.context.createStudent()[1]
     463        msg = self.context.createStudent(view=self)[1]
    437464        self.flash(msg)
    438465        self.redirect(self.url(self.context))
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/applicantscontainermanagepage.pt

    r7811 r8314  
    3434    </div>
    3535    <div id="tab-2" tal:attributes="class view/tab2">
    36       <h3 i18n:translate="">Applicants</h3>
     36
     37    <input type="checkbox" onClick="toggle(this, 'val_id')" />
     38    <span  i18n:translate="">Select all</span>
     39    <br /><br />
     40
    3741      <table class="display dataTableManage">
    3842        <thead>
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_container_data.csv

    r8033 r8314  
    1 code,title,prefix,entry_level,year,application_category,description,startdate,enddate,strict_deadline,mode
    2 app2012,General Studies 2012/2013,app,100,2012,basic,"This text can been seen by anonymous users.
     1code,title,prefix,year,application_category,description,startdate,enddate,strict_deadline,mode
     2app2012,General Studies 2012/2013,app,2012,basic,"This text can been seen by anonymous users.
    33>>de<<
    44Dieser Text kann von anonymen Benutzern gelesen werden.",2012-03-01,2012-04-25,1,create
    5 app2013,General Studies 2013/2014,app,100,2012,basic,"This text can been seen by anonymous users.
     5app2013,General Studies 2013/2014,app,2012,basic,"This text can been seen by anonymous users.
    66>>de<<
    77Dieser Text kann von anonymen Benutzern gelesen werden.",2013-03-01,2013-04-25,1,create
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py

    r7811 r8314  
    2020"""
    2121import os
    22 from hurry.workflow.interfaces import IWorkflowInfo
     22from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    2323from zope.component import getUtility
    2424from waeup.kofa.testing import FunctionalLayer
     
    5454        (success, msg) = self.applicant.createStudent()
    5555        self.assertTrue(msg == 'Applicant has not yet been admitted.')
    56         IWorkflowInfo(self.applicant).fireTransition('start')
    57         IWorkflowInfo(self.applicant).fireTransition('pay')
    58         IWorkflowInfo(self.applicant).fireTransition('submit')
    59         IWorkflowInfo(self.applicant).fireTransition('admit')
     56        IWorkflowState(self.applicant).setState('admitted')
    6057        (success, msg) = self.applicant.createStudent()
    6158        self.assertTrue(msg == 'No course admitted provided.')
     
    9996        self.assertMatches('...John Tester...', self.browser.contents)
    10097
     98    def test_batch_copying(self):
     99        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     100        self.browser.open(self.manage_path)
     101        self.fill_correct_values()
     102        self.browser.getControl("Save").click()
     103        # Upload a passport picture
     104        ctrl = self.browser.getControl(name='form.passport')
     105        file_obj = open(
     106            os.path.join(os.path.dirname(__file__), 'test_image.jpg'),'rb')
     107        file_ctrl = ctrl.mech_control
     108        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
     109        self.browser.getControl("Save").click() # submit form
     110        IWorkflowState(self.applicant).setState('admitted')
     111        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
     112        self.browser.getControl("Save").click()
     113        self.browser.open(self.manage_container_path)
     114        self.browser.getControl("Create students from selected", index=0).click()
     115        self.assertTrue('No applicant selected' in self.browser.contents)
     116        ctrl = self.browser.getControl(name='val_id')
     117        ctrl.getControl(value=self.applicant.application_number).selected = True
     118        self.browser.getControl("Create students from selected", index=0).click()
     119        self.assertTrue('1 students successfully created' in self.browser.contents)
     120
    101121    def test_copier_wo_passport(self):
    102122        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     
    104124        self.fill_correct_values()
    105125        # Let's try to create the student
    106         IWorkflowInfo(self.applicant).fireTransition('start')
    107         IWorkflowInfo(self.applicant).fireTransition('pay')
    108         IWorkflowInfo(self.applicant).fireTransition('submit')
    109         IWorkflowInfo(self.applicant).fireTransition('admit')
     126        IWorkflowState(self.applicant).setState('admitted')
    110127        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
    111128        self.browser.getControl("Save").click()
Note: See TracChangeset for help on using the changeset viewer.