[1310] | 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 | """ |
---|
| 13 | import logging |
---|
| 14 | logger = logging.getLogger('DeleteStudentByMatricNo') |
---|
| 15 | |
---|
| 16 | request = REQUEST |
---|
| 17 | wftool = context.portal_workflow |
---|
| 18 | mtool = context.portal_membership |
---|
| 19 | member = mtool.getAuthenticatedMember() |
---|
| 20 | roles = member.getRolesInContext(context) |
---|
| 21 | stdir = context.portal_directories.students |
---|
| 22 | st_cat = context.students_catalog |
---|
| 23 | ret_imp = context.returning_import |
---|
| 24 | res_imp = context.results_import |
---|
| 25 | students = context.portal_url.getPortalObject().campus.students |
---|
| 26 | if str(member) not in ('admin','joachim') or matric_no is None: |
---|
| 27 | return |
---|
| 28 | res = st_cat(matric_no=matric_no) |
---|
| 29 | if len(res) != 1: |
---|
| 30 | msg = "Student with matric_no %s not found in students_catalog" % matric_no |
---|
| 31 | logger.info(msg) |
---|
| 32 | return msg |
---|
| 33 | stbrain = res[0] |
---|
| 34 | #from Products.zdb import set_trace;set_trace() |
---|
| 35 | student_id = stbrain.id |
---|
| 36 | res_deleted = [] |
---|
| 37 | output = [] |
---|
| 38 | resi = ret_imp(matric_no=matric_no) |
---|
| 39 | if len(res) != 1: |
---|
| 40 | msg = "Student with matric_no %s not found in students_import" % matric_no |
---|
| 41 | logger.info(msg) |
---|
| 42 | else: |
---|
| 43 | msg = "Student with matric_no %s removed from students_import" % matric_no |
---|
| 44 | logger.info(msg) |
---|
| 45 | output.append(msg) |
---|
| 46 | results = res_imp(matric_no=matric_no) |
---|
| 47 | if 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)) |
---|
| 52 | else: |
---|
| 53 | msg = "no results to delete for %s" % matric_no |
---|
| 54 | output.append(msg) |
---|
| 55 | logger.info(msg) |
---|
| 56 | if hasattr(stdir, student_id): |
---|
| 57 | stdir.deleteEntry(student_id) |
---|
| 58 | msg = "Student Directoryentry for %s deleted" % student_id |
---|
| 59 | else: |
---|
| 60 | msg = "No Student Directoryentry for %s" % student_id |
---|
| 61 | output.append(msg) |
---|
| 62 | logger.info(msg) |
---|
| 63 | if hasattr(students,student_id): |
---|
| 64 | students.manage_delObjects((student_id),) |
---|
| 65 | msg = "students entry for %s deleted" % student_id |
---|
| 66 | else: |
---|
| 67 | msg = "No students entry for %s" % student_id |
---|
| 68 | output.append(msg) |
---|
| 69 | logger.info(msg) |
---|
| 70 | return "\n".join(output) |
---|