source: WAeUP_SRP/trunk/skins/waeup_student/remove_students.py @ 17364

Last change on this file since 17364 was 5161, checked in by Henrik Bettermann, 15 years ago

remove some unused lines

File size: 3.6 KB
RevLine 
[2402]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
23aq_students = context.students_catalog.evalAdvancedQuery
24students_folder = context.portal_url.getPortalObject().campus.students
25stdir = context.portal_directories.students
26mtool = context.portal_membership
27member = mtool.getAuthenticatedMember()
28rget = REQUEST.form.get
29info = {}
30info['member'] = member
31info['is_so'] = context.isSectionOfficer()
32ids = info['choosen_ids'] = rget('ids',[])
33search_list = rget('search_string','')
34delete = rget('delete',None)
35info['search_string'] = search_list
36student_ids = search_list.split()
37students = []
38#set_trace()
39psm = ''
40deleted_list = []
41if delete:
42    if not ids:
43        psm = "Nothing selected!"
44    else:
45        for student_id in ids:
46            logger.info("%s started to remove student record %s" % (member,student_id))
47            if hasattr(students_folder,student_id):
48                students_folder.manage_delObjects((student_id),)
49                logger.info("%s successfully removed student object %s" % (member,student_id))
50            else:
51                logger.info("Student object %s not found" % (student_id))
52                continue
53            deleted_list.append(student_id)
54            # remove from directory
55            if hasattr(stdir, student_id):
56                stdir.deleteEntry(student_id)
57                logger.info("%s successfully deleted student directory entry %s" % (member,student_id))
58            else:
59                logger.info("Student directory entry %s not found" % (student_id))
60                continue
61            context.waeup_tool.removePictureFolder(student_id)
62        psm = "%s removed" % ' '.join(deleted_list)
63
64if student_ids:
[2416]65    brains = aq_students(In('id',student_ids) | In('matric_no', student_ids))
[2402]66    brains_dict = {}
67    if brains:
68        for b in brains:
[2416]69            if b.id in student_ids:
70                brains_dict[b.id] = b
71            elif b.matric_no in student_ids:
72                brains_dict[b.matric_no] = b
[2402]73    for student_id in student_ids:
74        student = {}
75        student['deleted'] = delete and student_id in ids
76        if student_id in brains_dict.keys():
[2570]77            brain = brains_dict[student_id]
78            student['id'] = brain.id
79            student['review_state'] = brain.review_state
80            student['jamb_reg_no'] = brain.jamb_reg_no
81            student['name'] = brain.name
82            student['matric_no'] = brain.matric_no
[2571]83            if brain.review_state == "deactivated":
[2570]84                student['found'] = True
85            else:
86                student['found'] = False
[2402]87        else:
88            student['found'] = False
89            student['id'] = student_id
90            student['jamb_reg_no'] = ""
91            student['name'] = "not found"
92            student['matric_no'] = ''
[2958]93            student['review_state'] = ''
[2402]94        student['show_checkbox'] = not student['deleted'] and student['found']
95        students.append(student)
96
97allowed = students_folder.isSectionOfficer()
98
99return context.remove_students_form(info = info,
100                                    students = students,
101                                    allowed = allowed,
102                                    psm = psm,
103                                    )
Note: See TracBrowser for help on using the repository browser.