Ignore:
Timestamp:
29 Apr 2012, 12:55:52 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement import of student transitions.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 added
3 edited

Legend:

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

    r8300 r8309  
    4141    IStudentStudyLevel, ICourseTicket,
    4242    IStudentOnlinePayment, IStudentVerdictUpdate)
    43 from waeup.kofa.students.workflow import  IMPORTABLE_STATES
     43from waeup.kofa.students.workflow import  (
     44    IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS)
    4445from waeup.kofa.utils.batching import BatchProcessor
    4546
     
    6465        return sorted(list(set(
    6566            ['student_id','reg_number','matric_number',
    66             'password', 'state'] + fields.keys())))
     67            'password', 'state', 'transition'] + fields.keys())))
    6768
    6869    def checkHeaders(self, headerfields, mode='create'):
     70        if 'state' in headerfields and 'transition' in headerfields:
     71            raise FatalCSVError(
     72                "State and transition can't be  imported at the same time!")
    6973        if not 'reg_number' in headerfields and not 'student_id' \
    7074            in headerfields and not 'matric_number' in headerfields:
     
    148152        pass
    149153
     154    def checkUpdateRequirements(self, obj, row, site):
     155        """Checks requirements the object must fulfill when being updated.
     156
     157        This method is not used in case of deleting or adding objects.
     158
     159        Returns error messages as strings in case of requirement
     160        problems.
     161        """
     162        transition = row.get('transition', IGNORE_MARKER)
     163        if transition not in (IGNORE_MARKER, ''):
     164            allowed_transitions = IWorkflowInfo(obj).getManualTransitionIds()
     165            if transition not in allowed_transitions:
     166                return 'Transition not allowed.'
     167        return None
     168
    150169    def updateEntry(self, obj, row, site):
    151170        """Update obj to the values given in row.
     
    173192            history.addMessage(msg)
    174193            row.pop('state')
     194        transition = row.get('transition', IGNORE_MARKER)
     195        if transition not in (IGNORE_MARKER, ''):
     196            value = row['transition']
     197            IWorkflowInfo(obj).fireTransition(value)
     198            row.pop('transition')
    175199
    176200        # apply other values...
     
    218242        errs, inv_errs, conv_dict =  converter.fromStringDict(
    219243            row, self.factory_name, mode=mode)
     244        if row.has_key('transition') and \
     245            not row['transition'] in IMPORTABLE_TRANSITIONS:
     246            if row['transition'] not in (IGNORE_MARKER, ''):
     247                errs.append(('transition','not allowed'))
    220248        if row.has_key('state') and \
    221249            not row['state'] in IMPORTABLE_STATES:
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py

    r8289 r8309  
    3737from waeup.kofa.students.student import Student
    3838from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
    39 from waeup.kofa.interfaces import IBatchProcessor
     39from waeup.kofa.interfaces import IBatchProcessor, FatalCSVError
    4040
    4141STUDENT_SAMPLE_DATA = open(
     
    5858
    5959STUDENT_HEADER_FIELDS_UPDATE2 = STUDENT_SAMPLE_DATA_UPDATE2.split(
     60    '\n')[0].split(',')
     61
     62STUDENT_SAMPLE_DATA_UPDATE3 = open(
     63    os.path.join(os.path.dirname(__file__), 'sample_student_data_update3.csv'),
     64    'rb').read()
     65
     66STUDENT_HEADER_FIELDS_UPDATE3 = STUDENT_SAMPLE_DATA_UPDATE3.split(
     67    '\n')[0].split(',')
     68
     69STUDENT_SAMPLE_DATA_UPDATE4 = open(
     70    os.path.join(os.path.dirname(__file__), 'sample_student_data_update4.csv'),
     71    'rb').read()
     72
     73STUDENT_HEADER_FIELDS_UPDATE4 = STUDENT_SAMPLE_DATA_UPDATE4.split(
    6074    '\n')[0].split(',')
    6175
     
    179193        self.csv_file_update2 = os.path.join(
    180194            self.workdir, 'sample_student_data_update2.csv')
     195        self.csv_file_update3 = os.path.join(
     196            self.workdir, 'sample_student_data_update3.csv')
     197        self.csv_file_update4 = os.path.join(
     198            self.workdir, 'sample_student_data_update4.csv')
    181199        self.csv_file_migration = os.path.join(
    182200            self.workdir, 'sample_student_data_migration.csv')
     
    186204        open(self.csv_file_update, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE)
    187205        open(self.csv_file_update2, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE2)
     206        open(self.csv_file_update3, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE3)
     207        open(self.csv_file_update4, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE4)
    188208        open(self.csv_file_migration, 'wb').write(STUDENT_SAMPLE_DATA_MIGRATION)
    189209        open(self.csv_file_duplicates, 'wb').write(STUDENT_SAMPLE_DATA_DUPLICATES)
     
    293313        assert claus.phone is None
    294314        shutil.rmtree(os.path.dirname(fin_file))
     315
     316    def test_import_update3(self):
     317        num, num_warns, fin_file, fail_file = self.processor.doImport(
     318            self.csv_file, STUDENT_HEADER_FIELDS)
     319        shutil.rmtree(os.path.dirname(fin_file))
     320        num, num_warns, fin_file, fail_file = self.processor.doImport(
     321            self.csv_file_update3, STUDENT_HEADER_FIELDS_UPDATE3, 'update')
     322        content = open(fail_file).read()
     323        self.assertEqual(
     324            content,
     325            'reg_number,student_id,transition,--ERRORS--\r\n'
     326            '<IGNORE>,X666666,request_clearance,Transition not allowed.\r\n'
     327            )
     328        self.assertEqual(num_warns,1)
     329        self.assertEqual(self.app['students']['Y777777'].state,'returning')
     330
     331    def test_import_update4(self):
     332        num, num_warns, fin_file, fail_file = self.processor.doImport(
     333            self.csv_file, STUDENT_HEADER_FIELDS)
     334        shutil.rmtree(os.path.dirname(fin_file))
     335        self.assertRaises(
     336            FatalCSVError, self.processor.doImport, self.csv_file_update4,
     337            STUDENT_HEADER_FIELDS_UPDATE4, 'update')
    295338
    296339    def test_import_remove(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/workflow.py

    r7996 r8309  
    152152        destination = VALIDATED),
    153153    )
     154
     155IMPORTABLE_TRANSITIONS = [i.transition_id for i in REGISTRATION_TRANSITIONS]
    154156
    155157LOCK_CLEARANCE_TRANS = ('reset2', 'request_clearance')
Note: See TracChangeset for help on using the changeset viewer.