source: WAeUP_SRP/base/skins/waeup_utilities/remove_students.py @ 2400

Last change on this file since 2400 was 2400, checked in by Henrik Bettermann, 17 years ago

some fixes and beautifications

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
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 2400 2007-10-19 15:36:36Z henrik $
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 = []
39#set_trace()
40psm = ''
41deleted_list = []
42if delete:
43    if not ids:
44        psm = "Nothing selected!"
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            deleted_list.append(student_id)
55            # remove from directory
56            if hasattr(stdir, student_id):
57                stdir.deleteEntry(student_id)
58                logger.info("%s deleted Student directory for %s" % (member,student_id))
59            else:
60                logger.info("No Student directory for %s" % (student_id))
61                continue
62            context.waeup_tool.removePictureFolder(student_id)
63           
64
65        psm = "%s removed" % ' '.join(deleted_list)
66if student_ids:
67    brains = aq_students(In('id',student_ids))
68    brains_dict = {}
69    if brains:
70        for b in brains:
71            brains_dict[b.id] = b
72    for student_id in student_ids:
73        student = {}
74        student['deleted'] = delete and student_id in ids
75        if student_id in brains_dict.keys():
76            student['found'] = True
77            student['id'] = brains_dict[student_id].id
78            student['jamb_reg_no'] = brains_dict[student_id].jamb_reg_no
79            student['name'] = brains_dict[student_id].name
80            student['matric_no'] = brains_dict[student_id].matric_no
81        else:
82            student['found'] = False
83            student['id'] = student_id
84            student['jamb_reg_no'] = ""
85            student['name'] = "not found"
86            student['matric_no'] = ''
87        student['show_checkbox'] = not student['deleted'] and student['found']
88        students.append(student)
89
90
91return context.remove_students_form(info = info,
92                                    students = students,
93                                    allowed = True,
94                                    psm = psm,
95                                    )
Note: See TracBrowser for help on using the repository browser.