Changeset 8334


Ignore:
Timestamp:
3 May 2012, 20:43:02 (13 years ago)
Author:
Henrik Bettermann
Message:

Update password and state correctly.

Fix and improve logging. Do not log initial transition. They are always performed twice (due to applicant creation in converter).

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

Legend:

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

    r8331 r8334  
    204204        parent = self.getParent(row, site)
    205205        parent.addApplicant(obj)
    206         # We have to log this if state is provided. If not,
    207         # logging is done by the event handler handle_applicant_added
    208         if row.has_key('state'):
    209             parent.__parent__.logger.info(
    210             '%s - Application initialized' % obj.applicant_id)
     206        #parent.__parent__.logger.info(
     207        #    'Applicant imported: %s' % obj.applicant_id)
    211208        history = IObjectHistory(obj)
    212         history.addMessage(_('Application initialized'))
     209        history.addMessage(_('Application record imported'))
    213210        return
    214211
     
    218215            parent = applicant.__parent__
    219216            del parent[applicant.application_number]
     217            #parent.__parent__.logger.info(
     218            #    'Applicant removed: %s' % applicant.applicant_id)
    220219        pass
    221220
     
    224223        """
    225224        items_changed = ''
    226 
    227225        # Remove application_number from row if empty
    228226        if row.has_key('application_number') and row['application_number'] in (
     
    235233            obj.applicant_id = u'%s_%s' % (
    236234                row['container_code'], row['application_number'])
     235            items_changed += ('%s=%s, ' % ('applicant_id', obj.applicant_id))
    237236            row.pop('application_number')
    238237
    239238        # Update password
    240         passwd = row.get('password', IGNORE_MARKER)
    241         if passwd not in ('', IGNORE_MARKER):
    242             IUserAccount(obj).setPassword(passwd)
     239        if row.has_key('password'):
     240            passwd = row.get('password', IGNORE_MARKER)
     241            if passwd not in ('', IGNORE_MARKER):
     242                IUserAccount(obj).setPassword(passwd)
     243                items_changed += ('%s=%s, ' % ('password', passwd))
    243244            row.pop('password')
    244245
    245246        # Update registration state
    246         state = row.get('state', IGNORE_MARKER)
    247         if state not in (IGNORE_MARKER, ''):
    248             value = row['state']
    249             IWorkflowState(obj).setState(value)
    250             msg = _("State '${a}' set", mapping = {'a':value})
    251             history = IObjectHistory(obj)
    252             history.addMessage(msg)
     247        if row.has_key('state'):
     248            state = row.get('state', IGNORE_MARKER)
     249            if state not in (IGNORE_MARKER, ''):
     250                IWorkflowState(obj).setState(state)
     251                msg = _("State '${a}' set", mapping = {'a':state})
     252                history = IObjectHistory(obj)
     253                history.addMessage(msg)
     254                items_changed += ('%s=%s, ' % ('state', state))
    253255            row.pop('state')
    254256
    255257        # apply other values...
    256         items_changed = super(ApplicantProcessor, self).updateEntry(
     258        items_changed += super(ApplicantProcessor, self).updateEntry(
    257259            obj, row, site)
    258260
    259261        # Log actions...
    260262        parent = self.getParent(row, site)
    261         if hasattr(obj,'application_number'):
     263        if self.getLocator(row) == 'container_code':
    262264            # Update mode: the applicant exists and we can get the applicant_id
    263265            parent.__parent__.logger.info(
    264                 '%s - Application record updated: %s'
    265                 % (obj.applicant_id, items_changed))
     266                'Applicant imported: %s' % items_changed)
    266267        else:
    267268            # Create mode: the applicant does not yet exist
    268             parent.logger.info('Application record imported: %s' % items_changed)
     269            parent.__parent__.logger.info(
     270                'Applicant updated: %s' % items_changed)
    269271        return items_changed
    270272
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_batching.py

    r8332 r8334  
    245245        open(self.csv_file_update2, 'wb').write(APPLICANT_SAMPLE_DATA_UPDATE2)
    246246
     247        self.logfile = os.path.join(
     248            self.app['datacenter'].storage, 'logs', 'applicants.log')
     249
    247250    def test_interface(self):
    248251        # Make sure we fulfill the interface contracts.
     
    289292        assert applicant.__implemented__.__name__ == (
    290293            'waeup.kofa.applicants.applicant.Applicant')
     294        logcontent = open(self.logfile).read()
     295        # Logging message from updateEntry,
     296        # create applicant with given application_number
     297        self.assertTrue(
     298            'Applicant imported: applicant_id=dp2011_1234, password=mypwd1, '
     299            'reg_number=1001, firstname=Aaren, middlename=Peter, lastname=Pieri, '
     300            'sex=m, course1=CERT1, date_of_birth=1990-01-02, email=xx@yy.zz' in
     301            logcontent)
     302        # create applicant with random application_number which is
     303        # not shown in the log file
     304        self.assertTrue(
     305            'Applicant imported: reg_number=1003, firstname=Aaren, '
     306            'middlename=Alfons, lastname=Berson, sex=m, course1=CERT1, '
     307            'date_of_birth=1990-01-04, email=xx@yy.zz' in
     308            logcontent)
    291309        shutil.rmtree(os.path.dirname(fin_file))
    292310
     
    327345        self.assertTrue(IUserAccount(container['1234']).checkPassword('mypwd1'))
    328346        # password of Finau is still unset
    329         self.assertEqual(IUserAccount(container['2345']).password,'')
     347        self.assertEqual(IUserAccount(container['2345']).password,None)
    330348        # reg_number of Finau has changed
    331349        self.assertEqual(container['2345'].reg_number, '6666')
     350        logcontent = open(self.logfile).read()
     351
     352        # Logging message from updateEntry,
     353        # reg_number is locator
     354        self.assertTrue(
     355            'Applicant updated: reg_number=1001, firstname=Aaren' in
     356            logcontent)
     357        # applicant_id is locator
     358        self.assertTrue(
     359            'Applicant updated: state=admitted, reg_number=6666, '
     360            'firstname=Alfons, applicant_id=dp2011_2345' in
     361            logcontent)
     362
    332363        shutil.rmtree(os.path.dirname(fin_file))
    333364
     
    350381            self.csv_file_update, APPLICANT_HEADER_FIELDS_UPDATE, 'remove')
    351382        self.assertEqual(num_warns,0)
    352         shutil.rmtree(os.path.dirname(fin_file))
     383        logcontent = open(self.logfile).read()
     384
     385        # Logging message from handle_applicant_transition_event
     386        self.assertTrue(
     387            'dp2011_1234 - Applicant record removed' in
     388            logcontent)
     389
     390        shutil.rmtree(os.path.dirname(fin_file))
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/workflow.py

    r8312 r8334  
    170170    history.addMessage(msg)
    171171    # In some tests we don't have a an applicants root or a user
    172     try:
    173         applicants_root = grok.getSite()['applicants']
    174         applicants_root.logger.info('%s - %s' % (obj.applicant_id,msg))
    175     except (TypeError, AttributeError):
    176         pass
     172    if event.transition.transition_id != 'init':
     173        try:
     174            applicants_root = grok.getSite()['applicants']
     175            applicants_root.logger.info('%s - %s' % (obj.applicant_id,msg))
     176        except (TypeError, AttributeError):
     177            pass
    177178    return
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/converters.py

    r8217 r8334  
    302302        obj = context
    303303        if isinstance(context, basestring):
     304            # If we log initialization transitions this
     305            # will create another (misleading) log entry
    304306            obj = createObject(context)
    305307
Note: See TracChangeset for help on using the changeset viewer.