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 | |
---|
14 | pm = context.portal_membership |
---|
15 | member = pm.getAuthenticatedMember() |
---|
16 | wftool = context.portal_workflow |
---|
17 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
18 | import logging |
---|
19 | logger = logging.getLogger('Skins.createReturningStudent') |
---|
20 | |
---|
21 | if not matric_no: |
---|
22 | return "No MatricNo" |
---|
23 | |
---|
24 | if 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 | |
---|
35 | matric_nos = context.returning_import.uniqueValuesFor('matric_no') |
---|
36 | count = 1 |
---|
37 | total = 0 |
---|
38 | logger.info('%s started createReturningStudent"' % (member)) |
---|
39 | letters = ('ABCDEFGHKLMNPQRSTUVWXYZ') |
---|
40 | lc = 0 |
---|
41 | for 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 |
---|
66 | logger.info('createReturningStudent finished (%s)' % (total)) |
---|