Ignore:
Timestamp:
25 Oct 2012, 12:01:23 (12 years ago)
Author:
Henrik Bettermann
Message:

Start implementation of a special customized processor for course tickets.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/batchprocessing.txt

    r9312 r9418  
    9898    'Applicant Processor', 'Applicants Container Processor',
    9999    'CertificateCourse Processor', 'Certificate Processor',
    100     'Course Processor', 'CourseTicket Processor',
     100    'Course Processor', 'Course Result Processor (special processor)',
     101    'CourseTicket Processor',
    101102    'Department Processor', 'Faculty Processor',
    102103    'Hostel Processor',
     
    105106    'StudentStudyLevel Processor',
    106107    'User Processor',
    107     'Verdict Processor (update only)']
     108    'Verdict Processor (special processor, update only)']
    108109
    109110    >>> importerselect.getControl('Faculty Processor').selected = True
  • main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py

    r9316 r9418  
    720720
    721721class StudentVerdictProcessor(StudentStudyCourseProcessor):
    722     """A batch processor for verdicts.
     722    """A special batch processor for verdicts.
    723723
    724724    Import verdicts and perform workflow transitions.
     
    728728    grok.name(util_name)
    729729
    730     name = u'Verdict Processor (update only)'
     730    name = u'Verdict Processor (special processor, update only)'
    731731    iface = IStudentVerdictUpdate
    732732    factory_name = 'waeup.StudentStudyCourse'
     
    793793        notify(grok.ObjectModifiedEvent(obj.__parent__))
    794794        return
     795
     796class CourseResultProcessor(CourseTicketProcessor):
     797    """A special batch processor for course results objects.
     798
     799    Import course results, compares session and creates study level.
     800    """
     801    grok.implements(IBatchProcessor)
     802    grok.provides(IBatchProcessor)
     803    grok.context(Interface)
     804    util_name = 'courseresultprocessor'
     805    grok.name(util_name)
     806
     807    name = u'Course Result Processor (special processor)'
     808    iface = ICourseTicket
     809    factory_name = 'waeup.CourseTicket'
     810
     811    location_fields = []
     812    additional_fields = ['level', 'code']
     813    additional_headers = ['level', 'code']
     814
     815    def getParent(self, row, site):
     816        student = self._getStudent(row, site)
     817        if student is None:
     818            return None
     819        return student['studycourse'].get(row['level'])
     820
     821    def getEntry(self, row, site):
     822        level = self.getParent(row, site)
     823        if level is None:
     824            return None
     825        return level.get(row['code'])
     826
     827    def updateEntry(self, obj, row, site):
     828        """Update obj to the values given in row.
     829        """
     830        items_changed = super(CourseTicketProcessor, self).updateEntry(
     831            obj, row, site)
     832        parent = self.getParent(row, site)
     833        student = self.getParent(row, site).__parent__.__parent__
     834        student.__parent__.logger.info(
     835            '%s - Course ticket in %s updated: %s'
     836            % (student.student_id,  parent.level, items_changed))
     837        return
     838
     839    def addEntry(self, obj, row, site):
     840        parent = self.getParent(row, site)
     841        catalog = getUtility(ICatalog, name='courses_catalog')
     842        entries = list(catalog.searchResults(code=(row['code'],row['code'])))
     843        obj.fcode = entries[0].__parent__.__parent__.__parent__.code
     844        obj.dcode = entries[0].__parent__.__parent__.code
     845        obj.title = entries[0].title
     846        if getattr(obj, 'credits', None) is None:
     847            obj.credits = entries[0].credits
     848        if getattr(obj, 'passmark', None) is None:
     849            obj.passmark = entries[0].passmark
     850        obj.semester = entries[0].semester
     851        parent[row['code']] = obj
     852        return
     853
     854    def delEntry(self, row, site):
     855        raise NotImplementedError('method not implemented')
     856
     857    def checkConversion(self, row, mode='ignore'):
     858        """Validates all values in row.
     859        """
     860        errs, inv_errs, conv_dict = super(
     861            CourseTicketProcessor, self).checkConversion(row, mode=mode)
     862
     863        # We have to check if course really exists.
     864        # This is not done by the converter.
     865        catalog = getUtility(ICatalog, name='courses_catalog')
     866        entries = catalog.searchResults(code=(row['code'],row['code']))
     867        if len(entries) == 0:
     868            errs.append(('code','non-existent'))
     869            return errs, inv_errs, conv_dict
     870        return errs, inv_errs, conv_dict
Note: See TracChangeset for help on using the changeset viewer.