source: WAeUP_SRP/trunk/skins/waeup_utilities/deleteStudentByMatricNo.py @ 17364

Last change on this file since 17364 was 1567, checked in by Henrik Bettermann, 18 years ago

new logging format Part 2

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1## Script (Python) "deleteStudentByMatricNo"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=REQUEST,matric_no=None
8##title=
9##
10# $Id: deleteStudentByMatricNo.py 1567 2007-03-17 08:34:51Z henrik $
11"""
12"""
13import logging
14logger = logging.getLogger('Skins.deleteStudentByMatricNo')
15
16request = REQUEST
17wftool = context.portal_workflow
18mtool = context.portal_membership
19member = mtool.getAuthenticatedMember()
20roles = member.getRolesInContext(context)
21stdir = context.portal_directories.students
22st_cat = context.students_catalog
23ret_imp = context.returning_import
24res_imp = context.results_import
25students = context.portal_url.getPortalObject().campus.students
26if str(member) not in ('admin','joachim') or matric_no is None:
27    return
28
29
30# remove from students_catalog
31
32res = st_cat(matric_no=matric_no)
33if len(res) != 1:
34    msg = "Student with matric_no %s not found in students_catalog" % matric_no
35    logger.info(msg)
36    return msg
37else:
38    stbrain = res[0]
39    student_id = stbrain.id
40    st_cat.deleteRecord(student_id)
41    msg = "Student with matric_no %s and student_id %s removed from students_catalog" % (matric_no,student_id)
42    output = []
43    logger.info(msg)
44    output.append(msg)
45
46# remove from returning_import
47
48res_ret = ret_imp(matric_no=matric_no)
49if len(res_ret) != 1:
50    msg = "Student with matric_no %s not found in returning_import" % matric_no
51    logger.info(msg)
52else:
53    ret_imp.deleteRecord(matric_no)
54    msg = "Student with matric_no %s removed from returning_import" % matric_no
55logger.info(msg)
56output.append(msg)
57
58# remove from results_import
59
60res_deleted = []
61res_res = res_imp(matric_no=matric_no)
62if len(res_res) > 0:
63    for r in res_res:
64        res_imp.deleteRecord(r.key)
65        res_deleted.append(r.key)
66    msg = "%s results deleted from results_import" % (',\n'.join(res_deleted))
67else:
68    msg = "No results to delete for %s from results_import" % matric_no
69output.append(msg)
70logger.info(msg)
71
72# remove objects
73
74if hasattr(students,student_id):
75    students.manage_delObjects((student_id),)
76    msg = "Student object for %s deleted" % student_id
77else:
78    msg = "No students object for %s" % student_id
79output.append(msg)
80logger.info(msg)
81
82# remove from directory
83
84if hasattr(stdir, student_id):
85    stdir.deleteEntry(student_id)
86    msg = "Student directory entry for %s deleted" % student_id
87else:
88    msg = "No Student directory entry for %s" % student_id
89output.append(msg)
90logger.info(msg)
91
92
93return "\n".join(output)
94
Note: See TracBrowser for help on using the repository browser.