Ignore:
Timestamp:
19 Apr 2012, 15:11:32 (13 years ago)
Author:
uli
Message:

Clean up student-component batching, playing well with changed base
batch-processor.

File:
1 edited

Legend:

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

    r8214 r8221  
    5959    factory_name = 'waeup.Student'
    6060
    61     mode = None
    62 
    6361    @property
    6462    def available_fields(self):
     
    154152        """Update obj to the values given in row.
    155153        """
     154        items_changed = ''
     155
    156156        # Remove student_id from row if empty
    157157        if row.has_key('student_id') and row['student_id'] is None:
    158158            row.pop('student_id')
    159         items_changed = ''
    160         for key, value in row.items():
    161             # Set student password and all fields declared in interface.
    162             if key == 'password' and value != '':
    163                 IUserAccount(obj).setPassword(value)
    164             elif key == 'reg_state':
    165                 IWorkflowState(obj).setState(value)
    166                 msg = _("State '${a}' set", mapping = {'a':value})
    167                 history = IObjectHistory(obj)
    168                 history.addMessage(msg)
    169             elif hasattr(obj, key):
    170                 # Set attribute to None if value is marked for deletion
    171                 #if value == DELETION_MARKER:
    172                 #    setattr(obj, key, None)
    173                 #elif value is not None:
    174                 #    setattr(obj, key, value)
    175                 #else:
    176                 #    # No change, no change log
    177                 #    continue
    178                 if value != '<IGNORE>':
    179                     setattr(obj, key, value)
    180                
    181                     items_changed += '%s=%s, ' % (key,value)
     159
     160        # Update password
     161        passwd = row.get('password', '')
     162        if passwd:
     163            IUserAccount(obj).setPassword(passwd)
     164            row.pop('password')
     165
     166        # Update registration state
     167        if 'reg_state' in row.keys():
     168            value = row['reg_state']
     169            IWorkflowState(obj).setState(value)
     170            msg = _("State '${a}' set", mapping = {'a':value})
     171            history = IObjectHistory(obj)
     172            history.addMessage(msg)
     173            row.pop('reg_state')
     174
     175        # apply other values...
     176        items_changed = super(StudentProcessor, self).updateEntry(
     177            obj, row, site)
     178
     179        # Log actions...
    182180        parent = self.getParent(row, site)
    183181        if hasattr(obj,'student_id'):
     
    189187            # Create mode: the student does not yet exist
    190188            parent.logger.info('Student data imported: %s' % items_changed)
    191         return
     189        return items_changed
    192190
    193191    def getMapping(self, path, headerfields, mode):
     
    198196        raw_header = reader.next()
    199197        for num, field in enumerate(headerfields):
    200             if field not in [
    201                 'student_id', 'reg_number', 'matric_number'] and mode == 'remove':
     198            if field not in ['student_id', 'reg_number', 'matric_number'
     199                             ] and mode == 'remove':
    202200                continue
    203201            if field == u'--IGNORE--':
     
    242240    location_fields = []
    243241
    244     mode = None
    245 
    246242    @property
    247243    def available_fields(self):
     
    302298        """Update obj to the values given in row.
    303299        """
    304         items_changed = ''
    305         for key, value in row.items():
    306             # Skip fields not declared in interface.
    307             if hasattr(obj, key):
    308                 # Set attribute to None if value is marked for deletion
    309                 setattr(obj, key, value)
    310                 if key == 'certificate':
    311                     value = value.code
    312 
    313                 #if value == DELETIONMARKER:
    314                 #    setattr(obj, key, None)
    315                 #elif value is not None:
    316                 #    setattr(obj, key, value)
    317                 #    if key == 'certificate':
    318                 #        value = value.code
    319                 items_changed += '%s=%s, ' % (key,value)
     300        items_changed = super(StudentStudyCourseProcessor, self).updateEntry(
     301            obj, row, site)
    320302        parent = self.getParent(row, site)
    321303        parent.__parent__.logger.info(
     
    331313        converter = IObjectConverter(self.iface)
    332314        errs, inv_errs, conv_dict =  converter.fromStringDict(
    333             row, self.factory_name)
     315            row, self.factory_name, mode=mode)
    334316        # We have to check if current_level is in range of certificate.
    335         # This is not done by the converter. This kind of conversion
    336         # checking does only work if a combination of certificate and
    337         # current_level is provided.
    338317        if conv_dict.has_key('certificate'):
    339           certificate = conv_dict['certificate']
    340           start_level = certificate.start_level
    341           end_level = certificate.end_level
    342           if conv_dict['current_level'] < start_level or \
    343               conv_dict['current_level'] > end_level+120:
     318          cert = conv_dict['certificate']
     319          if conv_dict['current_level'] < cert.start_level or \
     320              conv_dict['current_level'] > cert.end_level+120:
    344321              errs.append(('current_level','not in range'))
    345322        return errs, inv_errs, conv_dict
     
    360337    location_fields = []
    361338
    362     mode = None
    363 
    364339    @property
    365340    def available_fields(self):
     
    431406        converter = IObjectConverter(self.iface)
    432407        errs, inv_errs, conv_dict =  converter.fromStringDict(
    433             row, self.factory_name)
     408            row, self.factory_name, mode=mode)
    434409        # We have to check if level is a valid integer.
    435410        # This is not done by the converter.
     
    457432    location_fields = []
    458433
    459     mode = None
    460 
    461434    @property
    462435    def available_fields(self):
    463436        return sorted(list(set(
    464             ['student_id','reg_number','matric_number','level','code'] + getFields(
    465                 self.iface).keys())))
     437            ['student_id','reg_number','matric_number','level',
     438             'code'] + getFields(self.iface).keys())))
    466439
    467440    def checkHeaders(self, headerfields, mode='ignore'):
     
    538511        converter = IObjectConverter(self.iface)
    539512        errs, inv_errs, conv_dict =  converter.fromStringDict(
    540             row, self.factory_name)
     513            row, self.factory_name, mode=mode)
    541514        # We have to check if course really exists.
    542515        # This is not done by the converter.
     
    562535
    563536    location_fields = []
    564 
    565     mode = None
    566537
    567538    @property
     
    648619        converter = IObjectConverter(self.iface)
    649620        errs, inv_errs, conv_dict =  converter.fromStringDict(
    650             row, self.factory_name)
     621            row, self.factory_name, mode=mode)
    651622        # We have to check p_id.
    652623        p_id = row['p_id'].strip('#')
     
    699670        """Update obj to the values given in row.
    700671        """
    701         items_changed = ''
    702         for key, value in row.items():
    703             # Skip fields not declared in interface plus
    704             # current_session and current_level
    705             if hasattr(obj, key) and not key in [
    706                 'current_session','current_level']:
    707                 setattr(obj, key, value)
    708                 # Set attribute to None if value is marked for deletion
    709                 #if value == DELETIONMARKER:
    710                 #    setattr(obj, key, None)
    711                 #elif value is not None:
    712                 #    setattr(obj, key, value)
    713                 items_changed += '%s=%s, ' % (key,value)
     672        # Don't set current_session, current_level
     673        vals_to_set = dict((key, val) for key, val in row.items()
     674                           if key not in ('current_session','current_level'))
     675        items_changed = super(StudentVerdictProcessor, self).updateEntry(
     676            obj, vals_to_set, site)
    714677        parent = self.getParent(row, site)
    715678        parent.__parent__.logger.info(
     
    727690        converter = IObjectConverter(self.iface)
    728691        errs, inv_errs, conv_dict =  converter.fromStringDict(
    729             row, self.factory_name)
     692            row, self.factory_name, mode=mode)
    730693        return errs, inv_errs, conv_dict
Note: See TracChangeset for help on using the changeset viewer.