[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 1384 2007-02-01 09:21:47Z 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 |
---|
[1384] | 28 | |
---|
| 29 | |
---|
| 30 | # remove from students_catalog |
---|
| 31 | |
---|
[1310] | 32 | res = st_cat(matric_no=matric_no) |
---|
| 33 | if len(res) != 1: |
---|
| 34 | msg = "Student with matric_no %s not found in students_catalog" % matric_no |
---|
| 35 | logger.info(msg) |
---|
| 36 | return msg |
---|
[1384] | 37 | else: |
---|
| 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) |
---|
[1383] | 45 | |
---|
[1384] | 46 | # remove from returning_import |
---|
[1383] | 47 | |
---|
[1382] | 48 | res_ret = ret_imp(matric_no=matric_no) |
---|
| 49 | if len(res_ret) != 1: |
---|
| 50 | msg = "Student with matric_no %s not found in returning_import" % matric_no |
---|
[1310] | 51 | logger.info(msg) |
---|
| 52 | else: |
---|
[1382] | 53 | ret_imp.deleteRecord(matric_no) |
---|
| 54 | msg = "Student with matric_no %s removed from returning_import" % matric_no |
---|
[1310] | 55 | logger.info(msg) |
---|
| 56 | output.append(msg) |
---|
[1384] | 57 | |
---|
| 58 | # remove from results_import |
---|
| 59 | |
---|
| 60 | res_deleted = [] |
---|
[1382] | 61 | res_res = res_imp(matric_no=matric_no) |
---|
| 62 | if len(res_res) > 0: |
---|
| 63 | for r in res_res: |
---|
[1310] | 64 | res_imp.deleteRecord(r.key) |
---|
| 65 | res_deleted.append(r.key) |
---|
[1382] | 66 | msg = "%s results deleted from results_import" % (',\n'.join(res_deleted)) |
---|
[1310] | 67 | else: |
---|
[1382] | 68 | msg = "No results to delete for %s from results_import" % matric_no |
---|
[1310] | 69 | output.append(msg) |
---|
| 70 | logger.info(msg) |
---|
[1384] | 71 | |
---|
| 72 | # remove from directory |
---|
| 73 | |
---|
[1310] | 74 | if hasattr(stdir, student_id): |
---|
| 75 | stdir.deleteEntry(student_id) |
---|
[1316] | 76 | msg = "Student directory entry for %s deleted" % student_id |
---|
[1310] | 77 | else: |
---|
[1316] | 78 | msg = "No Student directory entry for %s" % student_id |
---|
[1310] | 79 | output.append(msg) |
---|
| 80 | logger.info(msg) |
---|
[1384] | 81 | |
---|
| 82 | # remove objects |
---|
| 83 | |
---|
[1310] | 84 | if hasattr(students,student_id): |
---|
| 85 | students.manage_delObjects((student_id),) |
---|
[1316] | 86 | msg = "Student object for %s deleted" % student_id |
---|
[1310] | 87 | else: |
---|
[1316] | 88 | msg = "No students object for %s" % student_id |
---|
[1310] | 89 | output.append(msg) |
---|
| 90 | logger.info(msg) |
---|
[1384] | 91 | |
---|
[1310] | 92 | return "\n".join(output) |
---|
[1384] | 93 | |
---|