[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 2601 2007-11-08 22:37:27Z 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_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
| 24 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 25 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 26 | stdir = context.portal_directories.students |
---|
| 27 | mtool = context.portal_membership |
---|
| 28 | member = mtool.getAuthenticatedMember() |
---|
| 29 | rget = REQUEST.form.get |
---|
| 30 | info = {} |
---|
| 31 | info['member'] = member |
---|
| 32 | info['is_so'] = context.isSectionOfficer() |
---|
| 33 | ids = info['choosen_ids'] = rget('ids',[]) |
---|
| 34 | search_list = rget('search_string','') |
---|
| 35 | delete = rget('delete',None) |
---|
| 36 | info['search_string'] = search_list |
---|
| 37 | student_ids = search_list.split() |
---|
| 38 | students = [] |
---|
| 39 | psm = '' |
---|
| 40 | deleted_list = [] |
---|
| 41 | if delete: |
---|
| 42 | if not ids: |
---|
| 43 | psm = "Nothing selected!" |
---|
| 44 | else: |
---|
| 45 | for student_id in ids: |
---|
| 46 | student = getattr(students_folder,student_id,None) |
---|
| 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') |
---|
[2571] | 51 | context.portal_workflow.doActionFor(student,'deactivate') |
---|
| 52 | logger.info("%s deactivated student %s" % (member,student_id)) |
---|
[2596] | 53 | deleted_list.append(student_id) |
---|
[2571] | 54 | else: |
---|
| 55 | logger.info("Student object %s not found" % (student_id)) |
---|
| 56 | continue |
---|
| 57 | psm = "%s deactivated" % ' '.join(deleted_list) |
---|
| 58 | |
---|
| 59 | if student_ids: |
---|
| 60 | brains = aq_students(In('id',student_ids) | In('matric_no', student_ids)) |
---|
| 61 | brains_dict = {} |
---|
| 62 | if brains: |
---|
| 63 | for b in brains: |
---|
| 64 | if b.id in student_ids: |
---|
| 65 | brains_dict[b.id] = b |
---|
| 66 | elif b.matric_no in student_ids: |
---|
| 67 | brains_dict[b.matric_no] = b |
---|
| 68 | for student_id in student_ids: |
---|
| 69 | student = {} |
---|
| 70 | student['deleted'] = delete and student_id in ids |
---|
| 71 | if student_id in brains_dict.keys(): |
---|
| 72 | brain = brains_dict[student_id] |
---|
| 73 | student['id'] = brain.id |
---|
| 74 | student['review_state'] = brain.review_state |
---|
| 75 | student['jamb_reg_no'] = brain.jamb_reg_no |
---|
| 76 | student['name'] = brain.name |
---|
| 77 | student['matric_no'] = brain.matric_no |
---|
| 78 | if brain.review_state == "deactivated": |
---|
| 79 | student['found'] = False |
---|
| 80 | else: |
---|
| 81 | student['found'] = True |
---|
| 82 | else: |
---|
| 83 | student['found'] = False |
---|
| 84 | student['id'] = student_id |
---|
| 85 | student['jamb_reg_no'] = "" |
---|
| 86 | student['name'] = "not found" |
---|
| 87 | student['matric_no'] = '' |
---|
| 88 | student['show_checkbox'] = not student['deleted'] and student['found'] |
---|
| 89 | students.append(student) |
---|
| 90 | |
---|
| 91 | allowed = students_folder.isSectionOfficer() |
---|
| 92 | |
---|
| 93 | return context.deactivate_students_form(info = info, |
---|
| 94 | students = students, |
---|
| 95 | allowed = allowed, |
---|
| 96 | psm = psm, |
---|
| 97 | ) |
---|