Ignore:
Timestamp:
21 Feb 2022, 09:39:05 (3 years ago)
Author:
Henrik Bettermann
Message:

Enable import of student history.

File:
1 edited

Legend:

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

    r16079 r16819  
    2727import unicodecsv as csv # XXX: csv ops should move to dedicated module.
    2828from time import time
     29from ast import literal_eval
    2930from datetime import datetime
    3031from zope.i18n import translate
     
    9293        return sorted(list(set(
    9394            ['student_id','reg_number','matric_number',
    94             'password', 'state', 'transition'] + fields.keys())))
     95            'password', 'state', 'transition', 'history'] + fields.keys())))
    9596
    9697    def checkHeaders(self, headerfields, mode='create'):
     
    227228            row.pop('password')
    228229
     230        # Replace entire history
     231        if 'history' in row:
     232            new_history = row.get('history', IGNORE_MARKER)
     233            if new_history not in (IGNORE_MARKER, ''):
     234                history = IObjectHistory(obj)
     235                history._annotations[
     236                    history.history_key] = literal_eval(new_history)
     237                items_changed += ('%s=%s, ' % ('history', new_history))
     238            row.pop('history')
     239
    229240        # Update registration state
    230241        if 'state' in row:
     
    233244                value = row['state']
    234245                IWorkflowState(obj).setState(value)
    235                 msg = _("State '${a}' set", mapping = {'a':value})
     246                msg = _("State '${a}' imported", mapping = {'a':value})
    236247                history = IObjectHistory(obj)
    237248                history.addMessage(msg)
     
    302313                row['state'] not in (IGNORE_MARKER, ''):
    303314                errs.append(('workflow','not allowed'))
    304                 return errs, inv_errs, conv_dict
    305315        if 'transition' in row:
    306316            if row['transition'] not in IMPORTABLE_TRANSITIONS:
     
    315325                    # be changed if empty.
    316326                    conv_dict['state'] = IGNORE_MARKER
     327        if 'history' in row:
     328            if row['history'] not in (IGNORE_MARKER, ''):
     329                try:
     330                    new_history = literal_eval(row['history'])
     331                except:
     332                    errs.append(('history','malformed string'))
    317333        try:
    318334            # Correct stud_id counter. As the IConverter for students
Note: See TracChangeset for help on using the changeset viewer.