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

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

call with ?matric_no=mmmm

  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1## Script (Python) "search_pins"
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 1310 2007-01-16 16:19:10Z joachim $
11"""
12"""
13import logging
14logger = logging.getLogger('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
28res = st_cat(matric_no=matric_no)
29if len(res) != 1:
30    msg = "Student with matric_no %s not found in students_catalog" % matric_no
31    logger.info(msg)
32    return msg
33stbrain = res[0]
34#from Products.zdb import set_trace;set_trace()
35student_id = stbrain.id
36res_deleted = []
37output = []
38resi = ret_imp(matric_no=matric_no)
39if len(res) != 1:
40    msg = "Student with matric_no %s not found in students_import" % matric_no
41    logger.info(msg)
42else:
43    msg = "Student with matric_no %s removed from students_import" % matric_no
44logger.info(msg)
45output.append(msg)
46results = res_imp(matric_no=matric_no)
47if len(results) > 0:
48    for r in results:
49        res_imp.deleteRecord(r.key)
50        res_deleted.append(r.key)
51    msg = "%s deleted" % (','.join(res_deleted))
52else:
53    msg = "no results to delete for %s" % matric_no
54output.append(msg)
55logger.info(msg)
56if hasattr(stdir, student_id):
57    stdir.deleteEntry(student_id)
58    msg = "Student Directoryentry for %s deleted" % student_id
59else:
60    msg = "No Student Directoryentry for %s" % student_id
61output.append(msg)
62logger.info(msg)
63if hasattr(students,student_id):
64    students.manage_delObjects((student_id),)
65    msg = "students entry for %s deleted" % student_id
66else:
67    msg = "No students entry for %s" % student_id
68output.append(msg)
69logger.info(msg)
70return "\n".join(output)
Note: See TracBrowser for help on using the repository browser.