[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 1316 2007-01-17 18:05:49Z henrik $ |
---|
| 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: |
---|
[1316] | 27 | return |
---|
[1310] | 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: |
---|
[1316] | 53 | msg = "No results to delete for %s" % matric_no |
---|
[1310] | 54 | output.append(msg) |
---|
| 55 | logger.info(msg) |
---|
| 56 | if hasattr(stdir, student_id): |
---|
| 57 | stdir.deleteEntry(student_id) |
---|
[1316] | 58 | msg = "Student directory entry for %s deleted" % student_id |
---|
[1310] | 59 | else: |
---|
[1316] | 60 | msg = "No Student directory entry for %s" % student_id |
---|
[1310] | 61 | output.append(msg) |
---|
| 62 | logger.info(msg) |
---|
| 63 | if hasattr(students,student_id): |
---|
| 64 | students.manage_delObjects((student_id),) |
---|
[1316] | 65 | msg = "Student object for %s deleted" % student_id |
---|
[1310] | 66 | else: |
---|
[1316] | 67 | msg = "No students object for %s" % student_id |
---|
[1310] | 68 | output.append(msg) |
---|
| 69 | logger.info(msg) |
---|
| 70 | return "\n".join(output) |
---|