source: WAeUP_SRP/base/skins/waeup_student/deactivate_students.py @ 2588

Last change on this file since 2588 was 2571, checked in by joachim, 17 years ago

new function deactivate student

  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
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 2571 2007-11-07 16:19:21Z joachim $
11"""
12remove a list of students
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20import logging
21logger = logging.getLogger('Skins.remove_students')
22from Products.AdvancedQuery import Eq, Between, Le,In
23#aq_portal = context.portal_catalog_real.evalAdvancedQuery
24aq_students = context.students_catalog.evalAdvancedQuery
25students_folder = context.portal_url.getPortalObject().campus.students
26stdir = context.portal_directories.students
27mtool = context.portal_membership
28member = mtool.getAuthenticatedMember()
29rget = REQUEST.form.get
30info = {}
31info['member'] = member
32info['is_so'] = context.isSectionOfficer()
33ids = info['choosen_ids'] = rget('ids',[])
34search_list = rget('search_string','')
35delete = rget('delete',None)
36info['search_string'] = search_list
37student_ids = search_list.split()
38students = []
39psm = ''
40deleted_list = []
41if 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            set_trace()
48            if student is not None:
49                context.portal_workflow.doActionFor(student,'deactivate')
50                logger.info("%s deactivated student  %s" % (member,student_id))
51            else:
52                logger.info("Student object %s not found" % (student_id))
53                continue
54        psm = "%s deactivated" % ' '.join(deleted_list)
55
56if student_ids:
57    brains = aq_students(In('id',student_ids) | In('matric_no', student_ids))
58    brains_dict = {}
59    if brains:
60        for b in brains:
61            if b.id in student_ids:
62                brains_dict[b.id] = b
63            elif b.matric_no in student_ids:
64                brains_dict[b.matric_no] = b
65    for student_id in student_ids:
66        student = {}
67        student['deleted'] = delete and student_id in ids
68        if student_id in brains_dict.keys():
69            brain = brains_dict[student_id]
70            student['id'] = brain.id
71            student['review_state'] = brain.review_state
72            student['jamb_reg_no'] = brain.jamb_reg_no
73            student['name'] = brain.name
74            student['matric_no'] = brain.matric_no
75            if brain.review_state == "deactivated":
76                student['found'] = False
77            else:
78                student['found'] = True
79        else:
80            student['found'] = False
81            student['id'] = student_id
82            student['jamb_reg_no'] = ""
83            student['name'] = "not found"
84            student['matric_no'] = ''
85        student['show_checkbox'] = not student['deleted'] and student['found']
86        students.append(student)
87
88allowed = students_folder.isSectionOfficer()
89
90return context.deactivate_students_form(info = info,
91                                    students = students,
92                                    allowed = allowed,
93                                    psm = psm,
94                                    )
Note: See TracBrowser for help on using the repository browser.