Changeset 1170 for WAeUP_SRP/trunk/skins


Ignore:
Timestamp:
1 Jan 2007, 18:08:45 (18 years ago)
Author:
joachim
Message:

createReturningStudent?matric_no=All,
now creates all students-baseobject. Commits every 100 objects
100 students with commit takes about 38 seconds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/skins/waeup_student/createReturningStudent.py

    r1169 r1170  
    2121#if str(member) not in ("admin","joachim"):
    2222#    return "not possible"
     23def createOne(student_brain):
     24    sid = context.waeup_tool.generateStudentId('?')
     25    students_folder.invokeFactory('Student', sid)
     26    student = getattr(students_folder,sid)
     27    wftool.doActionFor(student,'return')
     28    student.manage_setLocalRoles(sid, ['Owner',])
     29    jamb_reg_no = student_brain.Entryregno,
     30    context.students_catalog.addRecord(id = sid,
     31                                       matric_no = matric_no,
     32                                       jamb_reg_no = jamb_reg_no,
     33                                       sex = student_brain.Sex == "F",
     34                                       name = "%s %s %s" % (student_brain.Firstname,
     35                                                            student_brain.Middlename,
     36                                                            student_brain.Lastname)
     37                                    )
     38    return sid,jamb_reg_no
     39
    2340if not matric_no:
    2441    return "No MatricNo"
    2542
    26 if context.students_catalog(matric_no=matric_no):
    27     return "Student with %s already exists" % matric_no
    28 res = context.returning_import(matric_no = matric_no)
    29 if len(res) != 1:
    30     return "MatricNo %s not found in Returning Table" % matric_no
    31 student_brain = res[0]
    32 sid = context.waeup_tool.generateStudentId('?')
    33 students_folder.invokeFactory('Student', sid)
    34 logger.info('"%s","Created Student","%s", "%s" ' % (member,sid,matric_no))
    35 student = getattr(students_folder,sid)
    36 wftool.doActionFor(student,'return')
    37 student.manage_setLocalRoles(sid, ['Owner',])
    38 jamb_reg_no = student_brain.Entryregno,
    39 context.students_catalog.addRecord(id = sid,
    40                                    matric_no = matric_no,
    41                                    jamb_reg_no = jamb_reg_no,
    42                                    sex = student_brain.Sex == "F",
    43                                    name = "%s %s %s" % (student_brain.Firstname,
    44                                                         student_brain.Middlename,
    45                                                         student_brain.Lastname)
    46                                 )
    47 return "Student MatricNo %s, StudentId %s Jamb %s created" % (matric_no,sid,jamb_reg_no)
     43if matric_no != 'All':
     44    if context.students_catalog(matric_no=matric_no):
     45        return "Student with %s already exists" % matric_no
     46    res = context.returning_import(matric_no = matric_no)
     47    if len(res) != 1:
     48        return "MatricNo %s not found in Returning Table" % matric_no
     49    student_brain = res[0]
     50    #sid,jamb_reg_no = context.waeup_tool.createOne(student_brain)
     51    sid,jamb_reg_no = context.createOne(student_brain)
     52    logger.info('"%s","Created Student","%s", "%s" ' % (member,sid,matric_no))
     53    return "Student MatricNo %s, StudentId %s Jamb %s created" % (matric_no,sid,jamb_reg_no)
    4854
     55students = context.returning_import(emil="adf")
     56count = 1
     57total = 0
     58logger.info('"%s","Create Students start"' % (member))
     59#from Products.zdb import set_trace;set_trace()
     60for student in students:
     61    if context.students_catalog(matric_no=student.matric_no):
     62        logger.info('"Student already exists","%s"' % (student.matric_no))
     63        continue
     64    if count > 100:
     65        context.waeup_tool.createOne(student,commit=True)
     66        logger.info('"%s","Commited Students","%s", "%s" ' % (member,count,total))
     67        total += count
     68        count = 1
     69    else:
     70        context.waeup_tool.createOne(student)
     71        count += 1
     72logger.info('"%s","Create Students finish","%s"' % (member,total))
Note: See TracChangeset for help on using the changeset viewer.