Changeset 8290


Ignore:
Timestamp:
26 Apr 2012, 17:01:32 (12 years ago)
Author:
Henrik Bettermann
Message:

Enable import of password and state. When application_number is given in create mode, construct applicant_id accordingly (do not use id generator) and store applicant with this application_number in the respective container. Attention: application_number can be any string.

More tests will follow.

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

Legend:

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

    r8236 r8290  
    2323from zope.interface import Interface
    2424from zope.component import queryUtility
     25from hurry.workflow.interfaces import IWorkflowState
    2526from zope.catalog.interfaces import ICatalog
    2627from waeup.kofa.interfaces import (
    27     IBatchProcessor, IObjectConverter, FatalCSVError, IGNORE_MARKER)
     28    IBatchProcessor, IObjectConverter, FatalCSVError, IGNORE_MARKER,
     29    IObjectHistory, IUserAccount)
     30from waeup.kofa.interfaces import MessageFactory as _
    2831from waeup.kofa.utils.batching import BatchProcessor
    2932from waeup.kofa.applicants.interfaces import (
    3033    IApplicantsContainer, IApplicant, IApplicantUpdateByRegNo)
     34from waeup.kofa.applicants.workflow import  IMPORTABLE_STATES
    3135
    3236class ApplicantsContainerProcessor(BatchProcessor):
     
    8993    def available_fields(self):
    9094        return sorted(list(set(
    91             ['application_number','reg_number','container_code'] + getFields(
     95            ['application_number','reg_number',
     96            'container_code','state','password'] + getFields(
    9297                self.iface).keys())))
    9398
     
    150155        parent = self.getParent(row, site)
    151156        parent.addApplicant(obj)
     157        # We have to log this if state is provided. If not,
     158        # logging is done by the event handler handle_applicant_added
     159        if row.has_key('state'):
     160            parent.__parent__.logger.info(
     161            '%s - Application initialized' % obj.applicant_id)
     162        history = IObjectHistory(obj)
     163        history.addMessage(_('Application initialized'))
    152164        return
    153165
     
    158170            del parent[applicant.application_number]
    159171        pass
     172
     173    def updateEntry(self, obj, row, site):
     174        """Update obj to the values given in row.
     175        """
     176        items_changed = ''
     177
     178        # Remove application_number from row if empty
     179        if row.has_key('application_number') and row['application_number'] in (
     180            None, IGNORE_MARKER):
     181            row.pop('application_number')
     182
     183        # Update applicant_id fom application_number and container code
     184        # if application_number is given
     185        if row.has_key('application_number'):
     186            obj.applicant_id = u'%s_%s' % (
     187                row['container_code'], row['application_number'])
     188            row.pop('application_number')
     189
     190        # Update password
     191        passwd = row.get('password', IGNORE_MARKER)
     192        if passwd not in ('', IGNORE_MARKER):
     193            IUserAccount(obj).setPassword(passwd)
     194            row.pop('password')
     195
     196        # Update registration state
     197        state = row.get('state', IGNORE_MARKER)
     198        if state not in (IGNORE_MARKER, ''):
     199            value = row['state']
     200            IWorkflowState(obj).setState(value)
     201            msg = _("State '${a}' set", mapping = {'a':value})
     202            history = IObjectHistory(obj)
     203            history.addMessage(msg)
     204            row.pop('state')
     205
     206        # apply other values...
     207        items_changed = super(ApplicantProcessor, self).updateEntry(
     208            obj, row, site)
     209
     210        # Log actions...
     211        parent = self.getParent(row, site)
     212        if hasattr(obj,'application_number'):
     213            # Update mode: the applicant exists and we can get the applicant_id
     214            parent.__parent__.logger.info(
     215                '%s - Application record updated: %s'
     216                % (obj.applicant_id, items_changed))
     217        else:
     218            # Create mode: the applicant does not yet exist
     219            parent.logger.info('Application record imported: %s' % items_changed)
     220        return items_changed
    160221
    161222    def getMapping(self, path, headerfields, mode):
     
    186247        errs, inv_errs, conv_dict =  converter.fromStringDict(
    187248            row, self.factory_name, mode=mode)
     249        if row.has_key('state') and \
     250            not row['state'] in IMPORTABLE_STATES:
     251            if row['state'] not in (IGNORE_MARKER, ''):
     252                errs.append(('state','not allowed'))
     253            else:
     254                # state is an attribute of Applicant and must not
     255                # be changed if empty
     256                conv_dict['state'] = IGNORE_MARKER
     257        application_number = row.get('application_number', IGNORE_MARKER)
     258        if application_number in (IGNORE_MARKER, ''):
     259                conv_dict['application_number'] = IGNORE_MARKER
    188260        return errs, inv_errs, conv_dict
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/container.py

    r8008 r8290  
    8989            raise TypeError(
    9090                'ApplicantsContainers contain only IApplicant instances')
    91         applicant_id = generate_applicant_id(container=self)
    92         applicant.applicant_id = applicant_id
     91        if applicant.applicant_id is None:
     92            applicant_id = generate_applicant_id(container=self)
     93            applicant.applicant_id = applicant_id
    9394        self[applicant.application_number] = applicant
    9495        return
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_applicant_data.csv

    r8202 r8290  
    1 container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename
    2 dp2011,1001,Aaren,Pieri,1990-01-02,xx@yy.zz,CERT1,m,Peter
    3 dp2011,1002,Aaren,Finau,1990-01-03,xx@yy.zz,CERT1,m,Claus
    4 dp2011,1003,Aaren,Berson,1990-01-04,xx@yy.zz,CERT1,m,Alfons
     1application_number,container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename
     21234,dp2011,1001,Aaren,Pieri,1990-01-02,xx@yy.zz,CERT1,m,Peter
     32345,dp2011,1002,Aaren,Finau,1990-01-03,xx@yy.zz,CERT1,m,Claus
     4,dp2011,1003,Aaren,Berson,1990-01-04,xx@yy.zz,CERT1,m,Alfons
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_applicant_data_update.csv

    r8202 r8290  
    1 container_code,reg_number,firstname,middlename
    2 dp2011,1001,Aaren,
    3 dp2011,1002,Alfons,
    4 dp2011,1003,Abraham,
     1container_code,reg_number,firstname,middlename,state
     2dp2011,1001,Aaren,,
     3dp2011,1002,Alfons,,admitted
     4dp2011,1003,Abraham,,
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_applicant_data_update2.csv

    r8202 r8290  
    1 container_code,reg_number,firstname,middlename
    2 dp2011,1001,Aaren,XXX
    3 dp2011,1002,Alfons,XXX
    4 dp2011,1003,Abraham,XXX
     1container_code,reg_number,firstname,middlename,application_number
     2dp2011,1001,Aaren,XXX,
     3dp2011,1002,Alfons,XXX,
     4dp2011,1003,Abraham,XXX,
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_faulty_applicant_data.csv

    r8202 r8290  
    1 container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename
    2 dp2011,1001,Aaren,Pieri,01/02/1990,xx@yy.zz,CERT1,m,Claus
     1application_number,container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename
     2,dp2011,1001,Aaren,Pieri,01/02/1990,xx@yy.zz,CERT1,m,Claus
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_batching.py

    r8202 r8290  
    311311        num, num_warns, fin_file, fail_file = self.processor.doImport(
    312312            self.csv_file_update, APPLICANT_HEADER_FIELDS_UPDATE, 'update')
     313        #content = open(fail_file).read()
    313314        self.assertEqual(num_warns,0)
    314315        # The middlename import value was None.
     
    320321                break
    321322        self.assertEqual(applicant.middlename, 'Peter')
     323        # state of Pieri has not changed
     324        self.assertEqual(container['1234'].state,'initialized')
     325        # state of Finau has changed
     326        self.assertEqual(container['2345'].state,'admitted')
    322327        shutil.rmtree(os.path.dirname(fin_file))
    323328        # Now we import another file which clears all middlename attributes.
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/workflow.py

    r8260 r8290  
    3333NOT_ADMITTED = 'not admitted'
    3434CREATED = 'created'
     35
     36IMPORTABLE_STATES = (INITIALIZED, PAID, SUBMITTED, ADMITTED, NOT_ADMITTED)
    3537
    3638application_states_dict = {
Note: See TracChangeset for help on using the changeset viewer.