Ignore:
Timestamp:
27 Jan 2012, 16:33:02 (13 years ago)
Author:
Henrik Bettermann
Message:

Add history messages and log file entries when importing students.

Do not accept empty reg_state fields. If the the reg_state column exists a valid value must be provided.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
4 edited

Legend:

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

    r7513 r7522  
    3333from hurry.workflow.interfaces import IWorkflowState
    3434from waeup.sirp.interfaces import (
    35     IBatchProcessor, FatalCSVError, IObjectConverter, IUserAccount)
     35    IBatchProcessor, FatalCSVError, IObjectConverter, IUserAccount,
     36    IObjectHistory)
    3637from waeup.sirp.students.interfaces import (
    3738    IStudent, IStudentStudyCourseImport,
     
    3940from waeup.sirp.students.workflow import  IMPORTABLE_STATES
    4041from waeup.sirp.utils.batching import BatchProcessor
     42from waeup.sirp.utils.helpers import get_current_principal
    4143
    4244class StudentProcessor(BatchProcessor):
     
    131133        parent = self.getParent(row, site)
    132134        parent.addStudent(obj)
     135        # In some tests we don't have a students container or a user
     136        try:
     137            user = get_current_principal()
     138            parent.logger.info('%s - %s - Student record imported' % (
     139                user.id,obj.student_id))
     140            history = IObjectHistory(obj)
     141            history.addMessage('Student record imported')
     142        except (TypeError, AttributeError):
     143            pass
    133144        return
    134145
     
    145156        for key, value in row.items():
    146157            # Set student password and all fields declared in interface.
    147             if key == 'password':
     158            if key == 'password' and value != '':
    148159                IUserAccount(obj).setPassword(value)
    149160            elif key == 'reg_state':
    150161                IWorkflowState(obj).setState(value)
     162                msg = "State '%s' set" % value
     163                history = IObjectHistory(obj)
     164                history.addMessage(msg)
    151165            elif hasattr(obj, key):
    152166                setattr(obj, key, value)
     
    183197            row, self.factory_name)
    184198        if row.has_key('reg_state') and \
    185             row['reg_state'] is not None and \
    186199            not row['reg_state'] in IMPORTABLE_STATES:
    187             errs.append(('reg_state','not allowed'))
     200            if row['reg_state'] != '':
     201                errs.append(('reg_state','not allowed'))
     202            else:
     203                errs.append(('reg_state','no value provided'))
    188204        return errs, inv_errs, conv_dict
    189205
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/sample_student_data.csv

    r7513 r7522  
    1 firstname,lastname,reg_number,date_of_birth,matric_number,email,phone,reg_state
     1firstname,lastname,reg_number,date_of_birth,matric_number,email,phone
    22Aaren,Pieri,1,1990-01-02,100000,aa@aa.ng,1234
    3 Aaren,Finau,2,1990-01-03,100001,aa@aa.ng,1234,admitted
    4 Aaren,Berson,3,1990-01-04,100002,aa@aa.ng,1234,cleared
    5 John,Wolter,4,1990-01-04,100003,aa@aa.ng,1234,nonsense
     3Aaren,Finau,2,1990-01-03,100001,aa@aa.ng,1234
     4Aaren,Berson,3,1990-01-04,100002,aa@aa.ng,1234
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/sample_student_data_migration.csv

    r7515 r7522  
    33B123456,Aaren,Finau,2,1990-01-03,100001,aa@aa.ng,1234,mypw1,cleared
    44C123456,Aaren,Berson,3,1990-01-04,100002,aa@aa.ng,1234,mypw1,admitted
    5 D123456,John,Wolter,4,1990-01-04,100003,aa@aa.ng,1234,mypw1,nonsense
     5D123456,John,Wolter,4,1990-01-05,100003,aa@aa.ng,1234,mypw1,nonsense
     6E123456,John,Kennedy,5,1990-01-06,100004,aa@aa.ng,1234,
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_batching.py

    r7515 r7522  
    163163        num, num_warns, fin_file, fail_file = self.importer.doImport(
    164164            self.csv_file, STUDENT_HEADER_FIELDS)
    165         self.assertEqual(num_warns,1)
     165        self.assertEqual(num_warns,0)
    166166        assert len(self.app['students'].keys()) == 4
    167167        shutil.rmtree(os.path.dirname(fin_file))
     
    197197        num, num_warns, fin_file, fail_file = self.importer.doImport(
    198198            self.csv_file_migration, STUDENT_HEADER_FIELDS_MIGRATION)
    199         self.assertEqual(num_warns,1)
     199        self.assertEqual(num_warns,2)
    200200        assert len(self.app['students'].keys()) == 4
    201201        self.assertTrue('A123456' in self.app['students'].keys())
     
    206206        self.assertEqual(self.app['students']['B123456'].date_of_birth,
    207207            datetime.date(1990, 1, 3))
     208        history = ' '.join(self.app['students']['A123456'].history.messages)
     209        self.assertTrue(
     210            "State 'school fee paid' set by system" in history)
    208211        shutil.rmtree(os.path.dirname(fin_file))
    209212
Note: See TracChangeset for help on using the changeset viewer.