Ignore:
Timestamp:
21 Aug 2006, 14:29:27 (18 years ago)
Author:
joachim
Message:

import of full_time_students_results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Students.py

    r396 r398  
    1919p_home = Globals.package_home(globals())
    2020i_home = Globals.INSTANCE_HOME
     21MAX_TRANS = 1000
    2122
    2223class StudentsFolder(CPSDocument): ###(
     
    3233        """load Fulltime Studentdata from CSV values"""
    3334        #return
     35        import transaction
     36        tr_count = 0
    3437        name = 'short_full_time'
    3538        no_import = False
     
    6467                continue
    6568            certcode = makeCertificateCode(student.get('CourseMajor'))
    66             if sid in students_added:
    67                 em = 'Student with ID %(MatricNo)s %(fullname)s already exists in this import\n' % student
    68                 logger.info(em)
    69                 no_import.write(em)
    70                 no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
    71                 continue
     69##            if sid in students_added:
     70##                em = 'Student with ID %(MatricNo)s %(fullname)s already exists in this import\n' % student
     71##                logger.info(em)
     72##                no_import.write(em)
     73##                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
     74##                continue
    7275            s = studs.get(sid,None)
    7376            if certcode not in certs.keys():
     
    9295                s = getattr(self,sid)
    9396                students_added.append(sid)
     97                studs[sid] = s
    9498                s.invokeFactory('StudentPersonal','personal')
    9599                sp = s.personal
     
    153157                no_import.write(em)
    154158                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
     159            if tr_count > MAX_TRANS:
     160                #transaction.commit()
     161                #em = '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Transaction commited\n' % student
     162                logger.info(em)
     163                tr_count = 0
     164            tr_count += 1
    155165        return self.students.academics_contents()
    156166    ###)
    157167
    158     security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV")
     168    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###(
    159169    def loadFullTimeStudentsResultsFromCSV(self):
    160170        """load Fulltime Studentdata from CSV values"""
    161171        #return
    162         name = 'short_full_time_results_2004_2005.csv'
     172        import transaction
     173        tr_count = 0
     174        name = 'short_full_time_results_2004_2005'
    163175        no_import = False
    164176        if not no_import:
     
    177189        for s in l:
    178190            students[s.id] = s.getObject()
    179         courses = self.portal_catalog({'meta_type': "Course"})
     191        l = self.portal_catalog({'meta_type': "Course"})
     192        courses = {}
     193        for c in l:
     194            courses[c.id] = c.getObject()
    180195        for result in results:
    181196            sid = result.get('Matnumber')
    182197            if sid not in students.keys():               
    183                 em = 'Student with ID %(Matnumber)s not found\n' % student
    184                 logger.info(em)
    185                 no_import.write(em)
    186                 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % student)
     198                em = 'Student with ID %(Matnumber)s not found\n' % result
     199                logger.info(em)
     200                no_import.write(em)
     201                no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result)
    187202                continue
    188             if student.get('CosCode') not in courses:
    189                 em = 'Course with ID %(CosCode)s not found\n' % student
    190                 logger.info(em)
    191                 no_import.write(em)
    192                 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % student)
     203            course = result.get('CosCode')
     204            if course not in courses.keys():
     205                em = 'Course with ID %(CosCode)s not found\n' % result
     206                logger.info(em)
     207                no_import.write(em)
     208                no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result)
    193209                continue
    194             level = student.get('Level')
     210            level = result.get('Level')
    195211            try:
    196212                int(level)
    197213            except:
    198                 em = 'Result for Student with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % student
    199                 logger.info(em)
    200                 no_import.write(em)
    201                 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % student)
     214                em = 'Result for result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result
     215                logger.info(em)
     216                no_import.write(em)
     217                no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result)
    202218                continue
    203219            sf = students.get(sid)
     
    206222            if l is None:
    207223                #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
    208                 logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student)
     224                logger.info('Creating Level %(Level)s for %(Matnumber)s' % result)
    209225                sc.invokeFactory('StudyLevel', level)
    210226                l = getattr(sc, level)
     
    216232                second_s = getattr(l,'second')
    217233                second_s.getContent().edit(mapping={'Title': 'Second Semester'})
    218             snr = student.get('Semester')
     234            snr = result.get('Semester')
    219235            semester = getattr(l,'first')
    220             if snr == "1":
     236            if snr == "2":
    221237                semester = getattr(l,'second')
     238            logger.info('Creating CourseTicket %(CourseTicket)s in Level %(Level)s for %(Matnumber)s' % result)
     239            semester.invokeFactory('CourseTicket',course)
     240            ct = getattr(semester,course)
     241            d = {}
     242            d['ansbook'] = result.get('Ansbook')
     243            d['status'] = result.get('CosStuatus')
     244            d['score'] = result.get('Score')
     245            d['carry_level'] = result.get('CarryLevel')
     246            d['grade'] = result.get('Grade')
     247            d['weight'] = result.get('Weight')
     248            d['verdict'] = result.get('Verdict')
     249            d['import_id'] = result.get('id')
     250            gpa = result.get('GPA').replace(',','.')
     251            d['gpa'] = float(gpa)
     252            ct.getContent().edit(mapping = d)
     253            if tr_count > MAX_TRANS:
     254                transaction.commit()
     255                tr_count = 0
     256            tr_count += 1
     257        return self.students.academics_contents()
    222258           
    223                
    224                
    225 
     259###)
     260
     261           
    226262    security.declareProtected(View,"Title")
    227263    def Title(self):
Note: See TracChangeset for help on using the changeset viewer.