Ignore:
Timestamp:
20 Jul 2012, 08:56:34 (12 years ago)
Author:
Henrik Bettermann
Message:

Disable states and transitions which are not allowed for pg students. Not yet fully tested.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
5 edited

Legend:

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

    r9001 r9028  
    4343    IStudentOnlinePayment, IStudentVerdictUpdate)
    4444from waeup.kofa.students.workflow import  (
    45     IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS)
     45    IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS,
     46    FORBIDDEN_POSTGRAD_TRANS, FORBIDDEN_POSTGRAD_STATES)
    4647from waeup.kofa.utils.batching import BatchProcessor
    4748
     
    171172            if transition not in allowed_transitions:
    172173                return 'Transition not allowed.'
     174            if transition in FORBIDDEN_POSTGRAD_TRANS and \
     175                obj.is_postgrad:
     176                return 'Transition not allowed (pg student).'
     177        state = row.get('state', IGNORE_MARKER)
     178        if state not in (IGNORE_MARKER, ''):
     179            if state in FORBIDDEN_POSTGRAD_STATES and \
     180                obj.is_postgrad:
     181                return 'State not allowed (pg student).'
    173182        return None
    174183
     
    262271        errs, inv_errs, conv_dict =  converter.fromStringDict(
    263272            row, self.factory_name, mode=mode)
    264         if row.has_key('transition') and \
    265             not row['transition'] in IMPORTABLE_TRANSITIONS:
    266             if row['transition'] not in (IGNORE_MARKER, ''):
    267                 errs.append(('transition','not allowed'))
    268         if row.has_key('state') and \
    269             not row['state'] in IMPORTABLE_STATES:
    270             if row['state'] not in (IGNORE_MARKER, ''):
    271                 errs.append(('state','not allowed'))
    272             else:
    273                 # state is an attribute of Student and must not
    274                 # be changed if empty
    275                 conv_dict['state'] = IGNORE_MARKER
    276 
     273        if row.has_key('transition'):
     274            if row['transition'] not in IMPORTABLE_TRANSITIONS:
     275                if row['transition'] not in (IGNORE_MARKER, ''):
     276                    errs.append(('transition','not allowed'))
     277        if row.has_key('state'):
     278            if row['state'] not in IMPORTABLE_STATES:
     279                if row['state'] not in (IGNORE_MARKER, ''):
     280                    errs.append(('state','not allowed'))
     281                else:
     282                    # State is an attribute of Student and must not
     283                    # be changed if empty.
     284                    conv_dict['state'] = IGNORE_MARKER
    277285        try:
    278286            # Correct stud_id counter. As the IConverter for students
     
    435443        return errs, inv_errs, conv_dict
    436444
     445    def checkUpdateRequirements(self, obj, row, site):
     446        """Checks requirements the object must fulfill when being updated.
     447
     448        This method is not used in case of deleting or adding objects.
     449
     450        Returns error messages as strings in case of requirement
     451        problems.
     452        """
     453        current_level = row.get('current_level', None)
     454        if current_level == '999' and obj.state in FORBIDDEN_POSTGRAD_STATES:
     455            return 'Not a pg student.'
     456        return None
     457
    437458class StudentStudyLevelProcessor(StudentProcessorBase):
    438459    """A batch processor for IStudentStudyLevel objects.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r9026 r9028  
    5858from waeup.kofa.students.catalog import search
    5959from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID,
    60     CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED)
     60    CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED,
     61    FORBIDDEN_POSTGRAD_TRANS)
    6162from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
    6263from waeup.kofa.students.vocabularies import StudyLevelSource
     
    378379        allowed_transitions = [t for t in self.wf_info.getManualTransitions()
    379380            if not t[0].startswith('pay')]
     381        if self.context.is_postgrad:
     382            allowed_transitions = [t for t in allowed_transitions
     383                if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
    380384        return [dict(name='', title=_('No transition'))] +[
    381385            dict(name=x, title=y) for x, y in allowed_transitions]
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py

    r8920 r9028  
    2323import unittest
    2424import datetime
     25import grok
    2526from time import time
     27from zope.event import notify
    2628from zope.component import createObject
    2729from zope.component.hooks import setSite, clearSite
    2830from zope.interface.verify import verifyClass, verifyObject
     31from hurry.workflow.interfaces import IWorkflowState
    2932
    3033from waeup.kofa.app import University
     
    178181    def setup_student(self, student):
    179182        # set predictable values for `student`
    180         student.matric_number = u'M123456'
     183        student.matric_number = u'234'
    181184        student.adm_code = u'my adm code'
    182185        student.clearance_locked = False
    183186        student.clr_code = u'my clr code'
    184187        student.perm_address = u'Studentroad 21\nLagos 123456\n'
    185         student.reg_number = u'123456'
    186         student.student_id = u'A111111'
     188        student.reg_number = u'123'
    187189        student.firstname = u'Anna'
    188190        student.lastname = u'Tester'
     
    240242
    241243
    242 class StudentProcessorTest(FunctionalTestCase):
     244class StudentProcessorTest(StudentImportExportSetup):
    243245
    244246    layer = FunctionalLayer
     
    246248    def setUp(self):
    247249        super(StudentProcessorTest, self).setUp()
    248         # Setup a sample site for each test
    249         app = University()
    250         self.dc_root = tempfile.mkdtemp()
    251         app['datacenter'].setStoragePath(self.dc_root)
    252 
    253         # Prepopulate the ZODB...
    254         self.getRootFolder()['app'] = app
    255         # we add the site immediately after creation to the
    256         # ZODB. Catalogs and other local utilities are not setup
    257         # before that step.
    258         self.app = self.getRootFolder()['app']
    259         # Set site here. Some of the following setup code might need
    260         # to access grok.getSite() and should get our new app then
    261         setSite(app)
    262250
    263251        # Add student with subobjects
    264252        student = Student()
    265         student.firstname = u'Anna'
    266         student.lastname = u'Tester'
    267         student.reg_number = u'123'
    268         student.matric_number = u'234'
    269253        self.app['students'].addStudent(student)
     254        student = self.setup_student(student)
     255        notify(grok.ObjectModifiedEvent(student))
    270256        self.student = self.app['students'][student.student_id]
     257
    271258        self.processor = StudentProcessor()
    272259        self.workdir = tempfile.mkdtemp()
     
    292279        open(self.csv_file_duplicates, 'wb').write(STUDENT_SAMPLE_DATA_DUPLICATES)
    293280
    294     def tearDown(self):
    295         super(StudentProcessorTest, self).tearDown()
    296         shutil.rmtree(self.workdir)
    297         shutil.rmtree(self.dc_root)
    298         clearSite()
    299         return
    300 
    301281    def test_interface(self):
    302282        # Make sure we fulfill the interface contracts.
     
    350330        self.assertEqual(initial_stud_id, new_stud_id)
    351331        return
     332
     333    def test_checkUpdateRequirements(self):
     334        # Make sure that pg students can't be updated with wrong transition.
     335        err = self.processor.checkUpdateRequirements(self.student,
     336            dict(reg_number='1', state='returning'), self.app)
     337        self.assertTrue(err is None)
     338        self.certificate.study_mode = 'pg_ft'
     339        err = self.processor.checkUpdateRequirements(self.student,
     340            dict(reg_number='1', state='returning'), self.app)
     341        self.assertEqual(err, 'State not allowed (pg student).')
     342        IWorkflowState(self.student).setState('school fee paid')
     343        err = self.processor.checkUpdateRequirements(self.student,
     344            dict(reg_number='1', transition='reset6'), self.app)
     345        self.assertEqual(err, 'Transition not allowed (pg student).')
     346        err = self.processor.checkUpdateRequirements(self.student,
     347            dict(reg_number='1', transition='register_courses'), self.app)
     348        self.assertEqual(err, 'Transition not allowed (pg student).')
     349
    352350
    353351    def test_delEntry(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r8983 r9028  
    4848
    4949            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
    50             'Anna,Tester,M123456,M.,NG,"Studentroad 21\nLagos 123456\n",'
    51             '+234-123-12345#,123456,f,A111111,0,,created'
     50            'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",'
     51            '+234-123-12345#,123,f,A111111,0,,created'
    5252            in result
    5353            )
     
    6868
    6969            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
    70             'Anna,Tester,M123456,M.,NG,"Studentroad 21\nLagos 123456\n",'
    71             '+234-123-12345#,123456,f,A111111,0,,created'
     70            'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",'
     71            '+234-123-12345#,123,f,A111111,0,,created'
    7272            in result
    7373            )
     
    8787
    8888            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
    89             'Anna,Tester,M123456,M.,NG,"Studentroad 21\nLagos 123456\n",'
    90             '+234-123-12345#,123456,f,A111111,0,,created'
     89            'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",'
     90            '+234-123-12345#,123,f,A111111,0,,created'
    9191            in result
    9292            )
  • main/waeup.kofa/trunk/src/waeup/kofa/students/workflow.py

    r9022 r9028  
    1717    REGISTERED, VALIDATED)
    1818
     19FORBIDDEN_POSTGRAD_STATES = (RETURNING, REGISTERED, VALIDATED)
     20
    1921REGISTRATION_TRANSITIONS = (
    2022    Transition(
     
    183185IMPORTABLE_TRANSITIONS = [i.transition_id for i in REGISTRATION_TRANSITIONS]
    184186
     187FORBIDDEN_POSTGRAD_TRANS = ['reset6', 'register_courses']
    185188LOCK_CLEARANCE_TRANS = ('reset2', 'request_clearance')
    186189UNLOCK_CLEARANCE_TRANS = ('reset3', 'reset4', 'start_clearance')
Note: See TracChangeset for help on using the changeset viewer.