source: WAeUP_SRP/trunk/skins/waeup_default/id_rename.py @ 4305

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

new cest application layout beautified

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1##parameters=
2# $Id: id_rename.py 2743 2007-11-22 21:42:57Z henrik $
3"""
4Rename objects which ids are passed in the request.
5
6Used within the folder_contents template.
7"""
8try:
9    from Products.zdb import set_trace
10except:
11    def set_trace():
12        pass
13import logging
14logger = logging.getLogger('Skins.id_rename')
15mtool = context.portal_membership
16member = mtool.getAuthenticatedMember()
17
18REQUEST = context.REQUEST
19
20if context.portal_type in ('CoursesFolder',):
21    return REQUEST.RESPONSE.redirect(context.absolute_url() + \
22                                ('/academics_index?portal_status_message=%s' \
23                                % ('Courses cannot be renamed',)))
24
25old_ids = REQUEST['ids']
26new_ids = REQUEST['new_ids']
27#new_ids = [id.upper() for id in REQUEST['new_ids']]
28
29here = context
30if context.portal_type == "University":
31    here = context.academics
32pt = context.portal_type
33mt = context.meta_type
34logger.info('%s started renaming %s to %s' % (member,old_ids,new_ids))
35
36here.manage_renameObjects(REQUEST['ids'], new_ids, REQUEST)
37if pt == 'University':
38    for faculty in old_ids:
39        students = context.students_catalog(faculty=faculty)
40        student_ids = [s.id for s in students]
41        data = {}
42        new_fid = new_ids[old_ids.index(faculty)]
43        data['faculty'] = new_fid
44        for sid in student_ids:
45            data['id'] = sid
46            context.students_catalog.modifyRecord(**data)
47        courses = context.courses_catalog(faculty=faculty)
48        courses_ids = [c.code for c in courses]
49        for cid in courses_ids:
50            data['code'] = cid
51            context.courses_catalogModify(**data)
52elif pt == 'Faculty':
53    for department in old_ids:
54        students = context.students_catalog(department=department)
55        student_ids = [s.id for s in students]
56        data = {}
57        new_did = new_ids[old_ids.index(department)]
58        data['department'] = new_did
59        for sid in student_ids:
60            data['id'] = sid
61            context.students_catalog.modifyRecord(**data)
62        courses = context.courses_catalog(department=department)
63        courses_ids = [c.code for c in courses]
64        for cid in courses_ids:
65            data['code'] = cid
66            context.courses_catalogModify(**data)
67logger.info('%s finished renaming %s to %s' % (member,old_ids,new_ids))
68
69return REQUEST.RESPONSE.redirect(here.absolute_url() + \
70                                ('?portal_status_message=%s' \
71                                % ('psm_item(s)_renamed',)))
Note: See TracBrowser for help on using the repository browser.