## Script (Python) "search_pins" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST,matric_no=None ##title= ## # $Id: deleteStudentByMatricNo.py 1350 2007-01-25 17:54:18Z joachim $ """ """ import logging logger = logging.getLogger('DeleteStudentByMatricNo') request = REQUEST wftool = context.portal_workflow mtool = context.portal_membership member = mtool.getAuthenticatedMember() roles = member.getRolesInContext(context) stdir = context.portal_directories.students st_cat = context.students_catalog ret_imp = context.returning_import res_imp = context.results_import students = context.portal_url.getPortalObject().campus.students if str(member) not in ('admin','joachim') or matric_no is None: return res = st_cat(matric_no=matric_no) if len(res) != 1: msg = "Student with matric_no %s not found in students_catalog" % matric_no logger.info(msg) return msg stbrain = res[0] #from Products.zdb import set_trace;set_trace() student_id = stbrain.id res_deleted = [] output = [] resi = ret_imp(matric_no=matric_no) if len(res) != 1: msg = "Student with matric_no %s not found in students_import" % matric_no logger.info(msg) else: msg = "Student with matric_no %s removed from students_import" % matric_no logger.info(msg) output.append(msg) results = res_imp(matric_no=matric_no) if len(results) > 0: for r in results: res_imp.deleteRecord(r.key) res_deleted.append(r.key) msg = "%s results deleted" % (',\n'.join(res_deleted)) else: msg = "No results to delete for %s" % matric_no output.append(msg) logger.info(msg) if hasattr(stdir, student_id): stdir.deleteEntry(student_id) msg = "Student directory entry for %s deleted" % student_id else: msg = "No Student directory entry for %s" % student_id output.append(msg) logger.info(msg) if hasattr(students,student_id): students.manage_delObjects((student_id),) msg = "Student object for %s deleted" % student_id else: msg = "No students object for %s" % student_id output.append(msg) logger.info(msg) return "\n".join(output)