1 | ## Script (Python) "remove_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: remove_students.py 2396 2007-10-19 14:17:29Z joachim $ |
---|
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 |
---|
21 | logger = logging.getLogger('Skins.remove_students') |
---|
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 | #set_trace() |
---|
40 | psm = 'nothing done' |
---|
41 | deleted_list = [] |
---|
42 | if delete: |
---|
43 | if not ids: |
---|
44 | psm = "nothing checked" |
---|
45 | else: |
---|
46 | for student_id in ids: |
---|
47 | logger.info("%s deletes student %s" % (member,student_id)) |
---|
48 | if hasattr(students_folder,student_id): |
---|
49 | students_folder.manage_delObjects((student_id),) |
---|
50 | logger.info("%s deleted student object for %s" % (member,student_id)) |
---|
51 | else: |
---|
52 | logger.info("No student object for %s" % (student_id)) |
---|
53 | continue |
---|
54 | # remove from directory |
---|
55 | if hasattr(stdir, student_id): |
---|
56 | stdir.deleteEntry(student_id) |
---|
57 | logger.info("%s deleted Student directory for %s" % (member,student_id)) |
---|
58 | else: |
---|
59 | logger.info("No Student directory for %s" % (student_id)) |
---|
60 | continue |
---|
61 | context.waeup_tool.removePictureFolder(student_id) |
---|
62 | deleted_list.append(student_id) |
---|
63 | |
---|
64 | psm = "%s deleted" % ' '.join(deleted_list) |
---|
65 | if student_ids: |
---|
66 | brains = aq_students(In('id',student_ids)) |
---|
67 | brains_dict = {} |
---|
68 | if brains: |
---|
69 | for b in brains: |
---|
70 | brains_dict[b.id] = b |
---|
71 | for student_id in student_ids: |
---|
72 | student = {} |
---|
73 | student['deleted'] = delete and student_id in ids |
---|
74 | if student_id in brains_dict.keys(): |
---|
75 | student['found'] = True |
---|
76 | student['id'] = brains_dict[student_id].id |
---|
77 | student['jamb_reg_no'] = brains_dict[student_id].jamb_reg_no |
---|
78 | student['name'] = brains_dict[student_id].name |
---|
79 | student['matric_no'] = brains_dict[student_id].matric_no |
---|
80 | else: |
---|
81 | student['found'] = False |
---|
82 | student['id'] = student_id |
---|
83 | student['jamb_reg_no'] = "" |
---|
84 | student['name'] = "not found" |
---|
85 | student['matric_no'] = '' |
---|
86 | student['show_checkbox'] = not student['deleted'] and student['found'] |
---|
87 | students.append(student) |
---|
88 | |
---|
89 | |
---|
90 | return context.remove_students_form(info = info, |
---|
91 | students = students, |
---|
92 | allowed = True, |
---|
93 | psm = psm, |
---|
94 | ) |
---|