source: WAeUP_SRP/branches/regebro-noskins/skins/waeup_utilities/createReturningStudent.py

Last change on this file was 1413, checked in by Henrik Bettermann, 18 years ago

sex and level from returning_import not from students_catalog

File size: 2.4 KB
Line 
1## Script (Python) "createReturningStudent"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=matric_no=None
8##title=
9##
10# $Id: createReturningStudent.py 1151 2006-12-29 22:05:53Z joachim $
11''' create the Studentbase folder'''
12
13
14pm = context.portal_membership
15member = pm.getAuthenticatedMember()
16wftool = context.portal_workflow
17students_folder = context.portal_url.getPortalObject().campus.students
18import logging
19logger = logging.getLogger('createReturningStudent')
20
21if not matric_no:
22    return "No MatricNo"
23
24if matric_no != 'All':
25    if context.students_catalog(matric_no=matric_no):
26        return "Student with %s already exists" % matric_no
27    res = context.returning_import(matric_no = matric_no)
28    if len(res) != 1:
29        return "MatricNo %s not found in Returning Table" % matric_no
30    student_brain = res[0]
31    sid,jamb_reg_no = context.waeup_tool.createOne(students_folder,student_brain,'?')
32    logger.info('"%s","Created Student","%s", "%s" ' % (member,sid,matric_no))
33    return "Student MatricNo %s, StudentId %s (JAMBRegNo %s) created" % (matric_no,sid,jamb_reg_no)
34
35matric_nos = context.returning_import.uniqueValuesFor('matric_no')
36count = 1
37total = 0
38logger.info('"%s","Create Students start"' % (member))
39letters = ('ABCDEFGHKLMNPQRSTUVWXYZ')
40lc = 0
41for matric_no in matric_nos:
42    res = context.students_catalog(matric_no = matric_no)
43    if len(res) == 1:
44        #logger.info('"Student already exists","%s"' % (matric_no))
45        continue
46    elif len(res) > 1:
47        logger.info('"Student with multiple entries","%s","%s" ' % (matric_no,len(res)))
48        ids = [r.id for r in res if not r.id.startswith('A')]
49        #from Products.zdb import set_trace;set_trace()
50        for id in ids:
51            context.students_catalog.deleteRecord(id)
52        students_folder.manage_delObjects(ids)
53        logger.info('"deleted students","%s" ' % " ".join(ids))
54        continue
55    student = context.returning_import(matric_no=matric_no)[0]
56    letter = letters[lc]
57    lc += 1
58    if lc == len(letters):
59        lc = 0
60    context.waeup_tool.createOne(students_folder,student,letter)
61    logger.info('"Student created","%s"' % (matric_no))
62    count += 1
63    if count > 10:
64        logger.info('"%s","Committed Students","%s", "%s" ' % (member,count,total))
65        total += count
66        count = 1
67logger.info('"%s","Create Students finish","%s"' % (member,total))
Note: See TracBrowser for help on using the repository browser.