[2571] | 1 | ## Script (Python) "deactivate_students" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=REQUEST |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: deactivate_students.py 5163 2010-04-21 04:38:00Z henrik $ |
---|
| 11 | """ |
---|
| 12 | remove a list of students |
---|
| 13 | """ |
---|
| 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
| 19 | |
---|
| 20 | import logging |
---|
[2596] | 21 | logger = logging.getLogger('Skins.deactivate_students') |
---|
[2571] | 22 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 23 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 24 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 25 | stdir = context.portal_directories.students |
---|
| 26 | mtool = context.portal_membership |
---|
| 27 | member = mtool.getAuthenticatedMember() |
---|
| 28 | rget = REQUEST.form.get |
---|
| 29 | info = {} |
---|
| 30 | info['member'] = member |
---|
| 31 | info['is_so'] = context.isSectionOfficer() |
---|
| 32 | ids = info['choosen_ids'] = rget('ids',[]) |
---|
| 33 | search_list = rget('search_string','') |
---|
| 34 | delete = rget('delete',None) |
---|
| 35 | info['search_string'] = search_list |
---|
| 36 | student_ids = search_list.split() |
---|
| 37 | students = [] |
---|
| 38 | psm = '' |
---|
| 39 | deleted_list = [] |
---|
| 40 | if delete: |
---|
| 41 | if not ids: |
---|
| 42 | psm = "Nothing selected!" |
---|
| 43 | else: |
---|
| 44 | for student_id in ids: |
---|
| 45 | student = getattr(students_folder,student_id,None) |
---|
[2720] | 46 | student_state = context.portal_workflow.getInfoFor(student,'review_state',None) |
---|
[2571] | 47 | if student is not None: |
---|
[2596] | 48 | for object in student.objectValues(): |
---|
[2601] | 49 | if context.portal_workflow.getInfoFor(object,'review_state',None) in ('open','created'): |
---|
[2596] | 50 | context.portal_workflow.doActionFor(object,'close') |
---|
[2720] | 51 | try: |
---|
| 52 | context.portal_workflow.doActionFor(student,'deactivate') |
---|
| 53 | except: |
---|
| 54 | logger.info("%s failed to deactivate student %s in state %s" % (member,student_id,student_state)) |
---|
| 55 | deleted_list.append(student_id + ' (failed)') |
---|
| 56 | continue |
---|
| 57 | logger.info("%s deactivated student %s" % (member,student_id)) |
---|
[2596] | 58 | deleted_list.append(student_id) |
---|
[2571] | 59 | else: |
---|
| 60 | logger.info("Student object %s not found" % (student_id)) |
---|
| 61 | continue |
---|
[2720] | 62 | psm = "Deactivated: %s" % ' '.join(deleted_list) |
---|
[2571] | 63 | |
---|
| 64 | if student_ids: |
---|
| 65 | brains = aq_students(In('id',student_ids) | In('matric_no', student_ids)) |
---|
| 66 | brains_dict = {} |
---|
| 67 | if brains: |
---|
| 68 | for b in brains: |
---|
| 69 | if b.id in student_ids: |
---|
| 70 | brains_dict[b.id] = b |
---|
| 71 | elif b.matric_no in student_ids: |
---|
| 72 | brains_dict[b.matric_no] = b |
---|
| 73 | for student_id in student_ids: |
---|
| 74 | student = {} |
---|
| 75 | student['deleted'] = delete and student_id in ids |
---|
| 76 | if student_id in brains_dict.keys(): |
---|
| 77 | brain = brains_dict[student_id] |
---|
| 78 | student['id'] = brain.id |
---|
| 79 | student['review_state'] = brain.review_state |
---|
| 80 | student['jamb_reg_no'] = brain.jamb_reg_no |
---|
| 81 | student['name'] = brain.name |
---|
| 82 | student['matric_no'] = brain.matric_no |
---|
| 83 | if brain.review_state == "deactivated": |
---|
| 84 | student['found'] = False |
---|
| 85 | else: |
---|
| 86 | student['found'] = True |
---|
| 87 | else: |
---|
| 88 | student['found'] = False |
---|
| 89 | student['id'] = student_id |
---|
| 90 | student['jamb_reg_no'] = "" |
---|
| 91 | student['name'] = "not found" |
---|
[2729] | 92 | student['review_state'] = "" |
---|
[2571] | 93 | student['matric_no'] = '' |
---|
| 94 | student['show_checkbox'] = not student['deleted'] and student['found'] |
---|
| 95 | students.append(student) |
---|
| 96 | |
---|
| 97 | allowed = students_folder.isSectionOfficer() |
---|
| 98 | |
---|
| 99 | return context.deactivate_students_form(info = info, |
---|
| 100 | students = students, |
---|
| 101 | allowed = allowed, |
---|
| 102 | psm = psm, |
---|
| 103 | ) |
---|