Ignore:
Timestamp:
22 Mar 2012, 07:21:20 (13 years ago)
Author:
Henrik Bettermann
Message:

Add verdict processor.

File:
1 edited

Legend:

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

    r7933 r7951  
    3131from zope.event import notify
    3232from zope.catalog.interfaces import ICatalog
    33 from hurry.workflow.interfaces import IWorkflowState
     33from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
    3434from waeup.kofa.interfaces import (
    3535    IBatchProcessor, FatalCSVError, IObjectConverter, IUserAccount,
    36     IObjectHistory)
     36    IObjectHistory, VALIDATED)
    3737from waeup.kofa.students.interfaces import (
    3838    IStudent, IStudentStudyCourse,
    3939    IStudentUpdateByRegNo, IStudentUpdateByMatricNo,
    4040    IStudentStudyLevel, ICourseTicket,
    41     IStudentOnlinePayment)
     41    IStudentOnlinePayment, IStudentVerdictUpdate)
    4242from waeup.kofa.students.workflow import  IMPORTABLE_STATES
    4343from waeup.kofa.utils.batching import BatchProcessor
     
    639639                return errs, inv_errs, conv_dict
    640640        return errs, inv_errs, conv_dict
     641
     642class StudentVerdictProcessor(StudentStudyCourseProcessor):
     643    """A batch processor for verdicts.
     644
     645    Import verdicts and perform workflow transitions.
     646    """
     647
     648    util_name = 'verdictupdater'
     649    grok.name(util_name)
     650
     651    name = u'Verdict Processor (update only)'
     652    iface = IStudentVerdictUpdate
     653    factory_name = 'waeup.StudentStudyCourse'
     654
     655    @property
     656    def available_fields(self):
     657        return sorted(list(set(
     658            ['student_id','reg_number','matric_number',
     659                'current_session', 'current_level'] + getFields(
     660                self.iface).keys())))
     661
     662    def checkUpdateRequirements(self, obj, row, site):
     663        """Checks requirements the studycourse and the student must fulfill
     664        before being updated.
     665        """
     666        # Check if current_levels correspond
     667        if obj.current_level != row['current_level']:
     668            return 'Current level does not correspond.'
     669        # Check if current_sessions correspond
     670        if obj.current_session != row['current_session']:
     671            return 'Current session does not correspond.'
     672        # Check if student is in state REGISTERED
     673        if obj.getStudent().state != VALIDATED:
     674            return 'Student in wrong state.'
     675        return None
     676
     677    def updateEntry(self, obj, row, site):
     678        """Update obj to the values given in row.
     679        """
     680        items_changed = ''
     681        for key, value in row.items():
     682            # Skip fields not declared in interface plus
     683            # current_verdict and current_level
     684            if hasattr(obj, key) and not key in [
     685                'current_verdict','current_level']:
     686                setattr(obj, key, value)
     687            items_changed += '%s=%s, ' % (key,value)
     688        parent = self.getParent(row, site)
     689        parent.__parent__.logger.info(
     690            '%s - Verdict updated: %s'
     691            % (parent.student_id, items_changed))
     692        # Fire transition
     693        IWorkflowInfo(obj.__parent__).fireTransition('return')
     694        # Update the students_catalog
     695        notify(grok.ObjectModifiedEvent(obj.__parent__))
     696        return
     697
     698    def checkConversion(self, row, mode='ignore'):
     699        """Validates all values in row.
     700        """
     701        converter = IObjectConverter(self.iface)
     702        errs, inv_errs, conv_dict =  converter.fromStringDict(
     703            row, self.factory_name)
     704        return errs, inv_errs, conv_dict
Note: See TracChangeset for help on using the changeset viewer.