source: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/createReturningStudent.py

Last change on this file was 1596, checked in by joachim, 18 years ago

merged changes from trunk to joachim-event-branch

File size: 2.3 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('Skins.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 creates 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 started createReturningStudent"' % (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        continue
45    elif len(res) > 1:
46        logger.info('Student %s with multiple entries (%s)' % (matric_no,len(res)))
47        # fix at the beginning
48        ids = [r.id for r in res if not r.id.startswith('A')]
49        for id in ids:
50            context.students_catalog.deleteRecord(id)
51        students_folder.manage_delObjects(ids)
52        logger.info('Student objects deleted: %s' % " ".join(ids))
53        continue
54    student = context.returning_import(matric_no=matric_no)[0]
55    letter = letters[lc]
56    lc += 1
57    if lc == len(letters):
58        lc = 0
59    context.waeup_tool.createOne(students_folder,student,letter)
60    logger.info('Student created: %s' % (matric_no))
61    count += 1
62    if count > 10:
63        logger.info('%s committed students %s, %s' % (member,count,total))
64        total += count
65        count = 1
66logger.info('createReturningStudent finished (%s)' % (total))
Note: See TracBrowser for help on using the repository browser.