[1674] | 1 | ## Script (Python) "deleteStudentByMatricNo" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=REQUEST,jamb_reg_no=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: deleteStudentByMatricNo.py 1567 2007-03-17 08:34:51Z henrik $ |
---|
| 11 | """ |
---|
| 12 | """ |
---|
| 13 | import logging |
---|
| 14 | logger = logging.getLogger('Skins.deleteStudentByRegNo') |
---|
| 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 jamb_reg_no is None: |
---|
| 27 | return |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | # remove from students_catalog |
---|
| 31 | |
---|
| 32 | res = st_cat(jamb_reg_no=jamb_reg_no) |
---|
| 33 | if len(res) != 1: |
---|
| 34 | msg = "Student with jamb_reg_no %s not found in students_catalog" % jamb_reg_no |
---|
| 35 | logger.info(msg) |
---|
| 36 | return msg |
---|
| 37 | else: |
---|
| 38 | stbrain = res[0] |
---|
| 39 | student_id = stbrain.id |
---|
| 40 | st_cat.deleteRecord(student_id) |
---|
| 41 | msg = "Student with jamb_reg_no %s and student_id %s removed from students_catalog" % (jamb_reg_no,student_id) |
---|
| 42 | output = [] |
---|
| 43 | logger.info(msg) |
---|
| 44 | output.append(msg) |
---|
| 45 | |
---|
| 46 | # remove objects |
---|
| 47 | |
---|
| 48 | if hasattr(students,student_id): |
---|
| 49 | students.manage_delObjects((student_id),) |
---|
| 50 | msg = "Student object for %s deleted" % student_id |
---|
| 51 | else: |
---|
| 52 | msg = "No students object for %s" % student_id |
---|
| 53 | output.append(msg) |
---|
| 54 | logger.info(msg) |
---|
| 55 | |
---|
| 56 | # remove from directory |
---|
| 57 | |
---|
| 58 | if hasattr(stdir, student_id): |
---|
| 59 | stdir.deleteEntry(student_id) |
---|
| 60 | msg = "Student directory entry for %s deleted" % student_id |
---|
| 61 | else: |
---|
| 62 | msg = "No Student directory entry for %s" % student_id |
---|
| 63 | output.append(msg) |
---|
| 64 | logger.info(msg) |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | return "\n".join(output) |
---|
| 68 | |
---|