Ignore:
Timestamp:
26 Apr 2012, 17:01:32 (13 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.