## Script (Python) "deactivate_students" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST ##title= ## # $Id: deactivate_students.py 2571 2007-11-07 16:19:21Z joachim $ """ remove a list of students """ try: from Products.zdb import set_trace except: def set_trace(): pass import logging logger = logging.getLogger('Skins.remove_students') from Products.AdvancedQuery import Eq, Between, Le,In #aq_portal = context.portal_catalog_real.evalAdvancedQuery aq_students = context.students_catalog.evalAdvancedQuery students_folder = context.portal_url.getPortalObject().campus.students stdir = context.portal_directories.students mtool = context.portal_membership member = mtool.getAuthenticatedMember() rget = REQUEST.form.get info = {} info['member'] = member info['is_so'] = context.isSectionOfficer() ids = info['choosen_ids'] = rget('ids',[]) search_list = rget('search_string','') delete = rget('delete',None) info['search_string'] = search_list student_ids = search_list.split() students = [] psm = '' deleted_list = [] if delete: if not ids: psm = "Nothing selected!" else: for student_id in ids: student = getattr(students_folder,student_id,None) set_trace() if student is not None: context.portal_workflow.doActionFor(student,'deactivate') logger.info("%s deactivated student %s" % (member,student_id)) else: logger.info("Student object %s not found" % (student_id)) continue psm = "%s deactivated" % ' '.join(deleted_list) if student_ids: brains = aq_students(In('id',student_ids) | In('matric_no', student_ids)) brains_dict = {} if brains: for b in brains: if b.id in student_ids: brains_dict[b.id] = b elif b.matric_no in student_ids: brains_dict[b.matric_no] = b for student_id in student_ids: student = {} student['deleted'] = delete and student_id in ids if student_id in brains_dict.keys(): brain = brains_dict[student_id] student['id'] = brain.id student['review_state'] = brain.review_state student['jamb_reg_no'] = brain.jamb_reg_no student['name'] = brain.name student['matric_no'] = brain.matric_no if brain.review_state == "deactivated": student['found'] = False else: student['found'] = True else: student['found'] = False student['id'] = student_id student['jamb_reg_no'] = "" student['name'] = "not found" student['matric_no'] = '' student['show_checkbox'] = not student['deleted'] and student['found'] students.append(student) allowed = students_folder.isSectionOfficer() return context.deactivate_students_form(info = info, students = students, allowed = allowed, psm = psm, )