1 | ##parameters= |
---|
2 | # $Id: id_rename.py 5225 2010-06-18 17:29:56Z henrik $ |
---|
3 | """ |
---|
4 | Rename objects which ids are passed in the request. |
---|
5 | |
---|
6 | Used within the folder_contents template. |
---|
7 | """ |
---|
8 | try: |
---|
9 | from Products.zdb import set_trace |
---|
10 | except: |
---|
11 | def set_trace(): |
---|
12 | pass |
---|
13 | import logging |
---|
14 | logger = logging.getLogger('Skins.id_rename') |
---|
15 | mtool = context.portal_membership |
---|
16 | member = mtool.getAuthenticatedMember() |
---|
17 | |
---|
18 | REQUEST = context.REQUEST |
---|
19 | |
---|
20 | if 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 | |
---|
25 | old_ids = REQUEST['ids'] |
---|
26 | new_ids = REQUEST['new_ids'] |
---|
27 | #new_ids = [id.upper() for id in REQUEST['new_ids']] |
---|
28 | |
---|
29 | here = context |
---|
30 | if context.portal_type == "University": |
---|
31 | here = context.academics |
---|
32 | pt = context.portal_type |
---|
33 | mt = context.meta_type |
---|
34 | logger.info('%s started renaming %s to %s' % (member,old_ids,new_ids)) |
---|
35 | |
---|
36 | here.manage_renameObjects(REQUEST['ids'], new_ids, REQUEST) |
---|
37 | if pt == 'AcademicsFolder': |
---|
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) |
---|
52 | elif 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) |
---|
67 | logger.info('%s finished renaming %s to %s' % (member,old_ids,new_ids)) |
---|
68 | |
---|
69 | return REQUEST.RESPONSE.redirect(here.absolute_url() + \ |
---|
70 | ('?portal_status_message=%s' \ |
---|
71 | % ('psm_item(s)_renamed',))) |
---|