Changeset 16819


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

Enable import of student history.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r16818 r16819  
    441.7.2.dev0 (unreleased)
    55=======================
     6
     7* Enable import of student history.
    68
    79* Don't complain but remove leading and trailing whitespaces
  • 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
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/sample_student_data.csv

    r15628 r16819  
    1 student_id,firstname,lastname,reg_number,date_of_birth,matric_number,email,phone,sex,state,password
    2 X666666,Aaren,Pieri,1,1990-01-02,100000,,1234,M,courses validated,test1234
    3 Y777777,Claus,Finau,2,1990-01-03,100001,aa@aa.ng,1234,m,courses validated,
    4 ,Susann,Berson,3,1990-01-04,100002,aa@aa.ng,1234,F,courses validated,
    5 ,Else,Mueller,4,1990-01-05,100003,aa@aa.ng,1234,f,school fee paid,
    6 ,,,,,,,,,,
    7 ,,,,  ,,, ,,,
    8 ,,,,<IGNORE>,,,<IGNORE>,,,
    9 X888888,Alfons,Meier,5,1990-01-02,100004,aa@aa.ng,1234,m,courses validated,
    10 X999999,Herbert,Mueller,6,1990-01-02,100005,aa@aa.ng,1234,m,courses registered,
    11 X111111,Fabian,Riester,7,1990-01-02,100006,aa@aa.ng,1234,m,courses validated,
    12 X222222,Thomas,Kinderman,8,1990-01-02,100007,aa@aa.ng,1234,m,courses validated,
    13 X333333,Paula,Schall,9,1990-01-02,100008,aa@aa.ng,1234,m,courses registered,
     1student_id,firstname,lastname,reg_number,date_of_birth,matric_number,email,phone,sex,state,password,history
     2X666666,Aaren,Pieri,1,1990-01-02,100000,,1234,M,courses validated,test1234,"[u'2012-10-23 00:05:39 WAT - Record created by System Admin', u'2012-10-23 00:05:39 WAT - Admitted by System Admin',u""2021-02-21 12:49:12 WAT - State 'graduated' set by System Admin""]"
     3Y777777,Claus,Finau,2,1990-01-03,100001,aa@aa.ng,1234,m,courses validated,,
     4,Susann,Berson,3,1990-01-04,100002,aa@aa.ng,1234,F,courses validated,,
     5,Else,Mueller,4,1990-01-05,100003,aa@aa.ng,1234,f,school fee paid,,
     6,,,,,,,,,,,
     7,,,,  ,,, ,,,,
     8,,,,<IGNORE>,,,<IGNORE>,,,,
     9X888888,Alfons,Meier,5,1990-01-02,100004,aa@aa.ng,1234,m,courses validated,,
     10X999999,Herbert,Mueller,6,1990-01-02,100005,aa@aa.ng,1234,m,courses registered,,
     11X111111,Fabian,Riester,7,1990-01-02,100006,aa@aa.ng,1234,m,courses validated,,
     12X222222,Thomas,Kinderman,8,1990-01-02,100007,aa@aa.ng,1234,m,courses validated,,
     13X333333,Paula,Schall,9,1990-01-02,100008,aa@aa.ng,1234,m,courses registered,,
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/sample_student_data_migration.csv

    r8355 r16819  
    1 student_id,firstname,lastname,reg_number,date_of_birth,matric_number,email,phone,password,sex,state
    2 A123456,Aaren,Pieri,1,1990-01-02#,100000,aa@aa.ng,1234,mypw1,m,clearance started
    3 B123456,Aaren,Finau,2,1990-01-03,100001,aa@aa.ng,1234,mypw1,m,cleared
    4 C123456,Aaren,Berson,3,1990-01-04,100002,aa@aa.ng,1234,{SSHA}JJBeA47pgGah500NFpuM2tVeLAbM8dxj,m,admitted
    5 D123456,John,Wolter,4,1990-01-05,100003,aa@aa.ng,1234,mypw1,m,nonsense
    6 E123456,John,Kennedy,5,1990-01-06,100004,aa@aa.ng,1234,,x,
    7 F123456,Frank,Meyer,6,1990-01-06,100005,aa@aa.ng,1234,,m,
     1student_id,firstname,lastname,reg_number,date_of_birth,matric_number,email,phone,password,sex,state,history
     2A123456,Aaren,Pieri,1,1990-01-02#,100000,aa@aa.ng,1234,mypw1,m,clearance started,"[u'2012-10-23 00:05:39 WAT - Record created by System Admin', u'2012-10-23 00:05:39 WAT - Admitted by System Admin',u""2021-02-21 12:49:12 WAT - State 'graduated' set by System Admin""]"
     3B123456,Aaren,Finau,2,1990-01-03,100001,aa@aa.ng,1234,mypw1,m,cleared,
     4C123456,Aaren,Berson,3,1990-01-04,100002,aa@aa.ng,1234,{SSHA}JJBeA47pgGah500NFpuM2tVeLAbM8dxj,m,admitted,
     5D123456,John,Wolter,4,1990-01-05,100003,aa@aa.ng,1234,mypw1,m,nonsense,
     6E123456,John,Kennedy,5,1990-01-06,100004,aa@aa.ng,1234,,x,,
     7F123456,Frank,Meyer,6,1990-01-06,100005,aa@aa.ng,1234,,m,,
     8G123456,Ulli,Meyer,7,1990-01-06,100007,aa@aa.ng,1234,,m,,nonsense
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py

    r16812 r16819  
    420420        self.assertEqual(
    421421            self.app['students']['X666666'].state, 'courses validated')
     422        # history was successfully impotrted
     423        history = self.app['students']['X666666'].history.messages
     424        self.assertEqual(history[0],
     425            '2012-10-23 00:05:39 WAT - Record created by System Admin')
     426        self.assertTrue(
     427            "State 'courses validated' imported by system" in history[3])
     428        # history import has been logged
     429        logcontent = open(self.logfile).read()
     430        self.assertTrue(
     431            "history=[u'2012-10-23 00:05:39 WAT - Record created by System Admin'"
     432            in logcontent)
    422433        # Two new student_ids have been created.
    423434        self.assertEqual(self.app['students']._curr_stud_id, 1000003)
     
    514525            self.csv_file_migration, STUDENT_HEADER_FIELDS_MIGRATION)
    515526        content = open(fail_file).read()
    516         self.assertEqual(num_warns,2)
     527        self.assertEqual(num_warns,3)
    517528        assert len(self.app['students'].keys()) == 5
    518529        self.assertEqual(
    519530            content,
    520             'reg_number,firstname,student_id,sex,email,phone,state,date_of_birth,lastname,password,matric_number,--ERRORS--\r\n'
    521             '4,John,D123456,m,aa@aa.ng,1234,nonsense,1990-01-05,Wolter,mypw1,100003,state: not allowed\r\n'
    522             '5,John,E123456,x,aa@aa.ng,1234,<IGNORE>,1990-01-06,Kennedy,<IGNORE>,100004,sex: Invalid value\r\n'
     531            'reg_number,firstname,student_id,sex,email,phone,state,date_of_birth,lastname,password,matric_number,history,--ERRORS--\r\n'
     532            '4,John,D123456,m,aa@aa.ng,1234,nonsense,1990-01-05,Wolter,mypw1,100003,<IGNORE>,state: not allowed\r\n'
     533            '5,John,E123456,x,aa@aa.ng,1234,<IGNORE>,1990-01-06,Kennedy,<IGNORE>,100004,<IGNORE>,sex: Invalid value\r\n'
     534            '7,Ulli,G123456,m,aa@aa.ng,1234,<IGNORE>,1990-01-06,Meyer,<IGNORE>,100007,nonsense,history: malformed string\r\n'
    523535            )
    524536        students = self.app['students']
     
    532544                         datetime.date(1990, 1, 3))
    533545        self.assertTrue(students['B123456'].clearance_locked)
    534         history = ' '.join(students['A123456'].history.messages)
     546        history = students['A123456'].history.messages
     547        self.assertEqual(history[0],
     548            '2012-10-23 00:05:39 WAT - Record created by System Admin')
    535549        self.assertTrue(
    536             "State 'clearance started' set by system" in history)
     550            "State 'clearance started' imported by system" in history[3])
    537551        # state was empty and student is thus in state created
    538552        self.assertEqual(students['F123456'].state,'created')
     
    723737        self.assertEqual(self.student.current_mode, 'ug_pt')
    724738        shutil.rmtree(os.path.dirname(fin_file))
    725         # Transer has bee logged.
     739        # Transfer has bee logged.
    726740        logcontent = open(self.logfile).read()
    727741        self.assertTrue(
Note: See TracChangeset for help on using the changeset viewer.