Ignore:
Timestamp:
21 Sep 2012, 08:19:35 (12 years ago)
Author:
uli
Message:

Rollback r9209. Looks like multiple merges from trunk confuse svn when merging back into trunk.

Location:
main/waeup.kofa/branches/uli-zc-async
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/branches/uli-zc-async

  • main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/batching.py

    r9209 r9211  
    2626import grok
    2727import csv
    28 from time import time
    2928from zope.interface import Interface
    3029from zope.schema import getFields
     
    4342    IStudentOnlinePayment, IStudentVerdictUpdate)
    4443from waeup.kofa.students.workflow import  (
    45     IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS,
    46     FORBIDDEN_POSTGRAD_TRANS, FORBIDDEN_POSTGRAD_STATES)
     44    IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS)
    4745from waeup.kofa.utils.batching import BatchProcessor
    4846
     
    172170            if transition not in allowed_transitions:
    173171                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).'
    182172        return None
    183173
     
    193183
    194184        # Update password
    195         # XXX: Tale DELETION_MARKER into consideration
    196185        if row.has_key('password'):
    197186            passwd = row.get('password', IGNORE_MARKER)
     
    233222        parent = self.getParent(row, site)
    234223        if hasattr(obj,'student_id'):
    235             # Update mode: the student exists and we can get the student_id.
    236             # Create mode: the record contains the student_id
     224            # Update mode: the student exists and we can get the student_id
    237225            parent.logger.info(
    238226                '%s - Student record updated: %s'
     
    271259        errs, inv_errs, conv_dict =  converter.fromStringDict(
    272260            row, self.factory_name, mode=mode)
    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
     261        if row.has_key('transition') and \
     262            not row['transition'] in IMPORTABLE_TRANSITIONS:
     263            if row['transition'] not in (IGNORE_MARKER, ''):
     264                errs.append(('transition','not allowed'))
     265        if row.has_key('state') and \
     266            not row['state'] in IMPORTABLE_STATES:
     267            if row['state'] not in (IGNORE_MARKER, ''):
     268                errs.append(('state','not allowed'))
     269            else:
     270                # state is an attribute of Student and must not
     271                # be changed if empty
     272                conv_dict['state'] = IGNORE_MARKER
     273
    285274        try:
    286275            # Correct stud_id counter. As the IConverter for students
     
    302291    grok.baseclass()
    303292
    304     # additional available  fields
    305     # beside 'student_id', 'reg_number' and 'matric_number'
     293    #: required fields beside 'student_id', 'reg_number' and 'matric_number'
    306294    additional_fields = []
    307295
    308     #: header fields additionally required
     296    #: header fields additional required
    309297    additional_headers = []
    310298
     
    373361        return errs, inv_errs, conv_dict
    374362
    375     def getMapping(self, path, headerfields, mode):
    376         """Get a mapping from CSV file headerfields to actually used fieldnames.
    377         """
    378         result = dict()
    379         reader = csv.reader(open(path, 'rb'))
    380         raw_header = reader.next()
    381         for num, field in enumerate(headerfields):
    382             if field not in ['student_id', 'reg_number', 'matric_number',
    383                              'p_id', 'code', 'level'
    384                              ] and mode == 'remove':
    385                 continue
    386             if field == u'--IGNORE--':
    387                 # Skip ignored columns in failed and finished data files.
    388                 continue
    389             result[raw_header[num]] = field
    390         return result
    391 
    392363
    393364class StudentStudyCourseProcessor(StudentProcessorBase):
     
    435406            StudentStudyCourseProcessor, self).checkConversion(row, mode=mode)
    436407        # We have to check if current_level is in range of certificate.
    437         if conv_dict.has_key('certificate') and \
    438             conv_dict.has_key('current_level'):
    439             cert = conv_dict['certificate']
    440             level = conv_dict['current_level']
    441             if level < cert.start_level or level > cert.end_level+120:
    442                 errs.append(('current_level','not in range'))
     408        if conv_dict.has_key('certificate'):
     409          cert = conv_dict['certificate']
     410          if conv_dict['current_level'] < cert.start_level or \
     411              conv_dict['current_level'] > cert.end_level+120:
     412              errs.append(('current_level','not in range'))
    443413        return errs, inv_errs, conv_dict
    444 
    445     def checkUpdateRequirements(self, obj, row, site):
    446         """Checks requirements the object must fulfill when being updated.
    447 
    448         Returns error messages as strings in case of requirement
    449         problems.
    450         """
    451         current_level = row.get('current_level', None)
    452         if current_level == 999 and \
    453             obj.__parent__.state in FORBIDDEN_POSTGRAD_STATES:
    454             return 'Not a pg student.'
    455         return None
    456414
    457415class StudentStudyLevelProcessor(StudentProcessorBase):
     
    469427
    470428    location_fields = []
    471 
    472429    additional_fields = ['level']
    473430    additional_headers = ['level']
     
    552509        items_changed = super(CourseTicketProcessor, self).updateEntry(
    553510            obj, row, site)
    554         parent = self.getParent(row, site)
    555511        student = self.getParent(row, site).__parent__.__parent__
    556512        student.__parent__.logger.info(
    557             '%s - Course ticket in %s updated: %s'
    558             % (student.student_id,  parent.level, items_changed))
     513            '%s - Course ticket updated: %s'
     514            % (student.student_id, items_changed))
    559515        return
    560516
     
    572528        return
    573529
    574     def delEntry(self, row, site):
    575         ticket = self.getEntry(row, site)
    576         parent = self.getParent(row, site)
    577         if ticket is not None:
    578             student = self._getStudent(row, site)
    579             student.__parent__.logger.info('%s - Course ticket in %s removed: %s'
    580                 % (student.student_id, parent.level, ticket.code))
    581             del parent[ticket.code]
    582         return
    583 
    584530    def checkConversion(self, row, mode='ignore'):
    585531        """Validates all values in row.
     
    606552    grok.name(util_name)
    607553
    608     name = u'Student Payment Processor'
     554    name = u'Payment Processor'
    609555    iface = IStudentOnlinePayment
    610556    factory_name = 'waeup.StudentOnlinePayment'
     
    612558    location_fields = []
    613559    additional_fields = ['p_id']
    614     additional_headers = []
    615 
    616     def checkHeaders(self, headerfields, mode='ignore'):
    617         super(StudentOnlinePaymentProcessor, self).checkHeaders(headerfields)
    618         if mode in ('update', 'remove') and not 'p_id' in headerfields:
    619             raise FatalCSVError(
    620                 "Need p_id for import in update and remove modes!")
    621         return True
     560    additional_headers = ['p_id']
    622561
    623562    def parentsExist(self, row, site):
     
    634573        if payments is None:
    635574            return None
    636         p_id = row.get('p_id', None)
    637         if p_id is None:
    638             return None
    639575        # We can use the hash symbol at the end of p_id in import files
    640576        # to avoid annoying automatic number transformation
    641577        # by Excel or Calc
    642         p_id = p_id.strip('#')
    643         if not p_id.startswith('p'):
    644             # For data migration from old SRP only
    645             p_id = 'p' + p_id[7:] + '0'
    646         entry = payments.get(p_id)
     578        p_id = row['p_id'].strip('#')
     579        if p_id.startswith('p'):
     580            entry = payments.get(p_id)
     581        else:
     582            # For data migration from old SRP
     583            entry = payments.get('p' + p_id[6:])
    647584        return entry
    648585
     
    663600        if not p_id.startswith('p'):
    664601            # For data migration from old SRP
    665             obj.p_id = 'p' + p_id[7:] + '0'
     602            obj.p_id = 'p' + p_id[6:]
    666603            parent[obj.p_id] = obj
    667604        else:
     
    669606        return
    670607
    671     def delEntry(self, row, site):
    672         payment = self.getEntry(row, site)
    673         parent = self.getParent(row, site)
    674         if payment is not None:
    675             student = self._getStudent(row, site)
    676             student.__parent__.logger.info('%s - Payment ticket removed: %s'
    677                 % (student.student_id, payment.p_id))
    678             del parent[payment.p_id]
    679         return
    680 
    681608    def checkConversion(self, row, mode='ignore'):
    682609        """Validates all values in row.
     
    686613
    687614        # We have to check p_id.
    688         p_id = row.get('p_id', None)
    689         if not p_id:
    690             timestamp = ("%d" % int(time()*10000))[1:]
    691             p_id = "p%s" % timestamp
    692             conv_dict['p_id'] = p_id
    693             return errs, inv_errs, conv_dict
    694         else:
    695             p_id = p_id.strip('#')
     615        p_id = row['p_id'].strip('#')
    696616        if p_id.startswith('p'):
    697617            if not len(p_id) == 14:
Note: See TracChangeset for help on using the changeset viewer.