[370] | 1 | ##parameters= |
---|
[486] | 2 | # $Id: id_rename.py 1724 2007-04-30 15:37:48Z joachim $ |
---|
[370] | 3 | """ |
---|
| 4 | Rename objects which ids are passed in the request. |
---|
| 5 | |
---|
| 6 | Used within the folder_contents template. |
---|
| 7 | """ |
---|
[1724] | 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() |
---|
[370] | 17 | |
---|
| 18 | REQUEST = context.REQUEST |
---|
| 19 | |
---|
[371] | 20 | if context.portal_type in ('CoursesFolder',): |
---|
| 21 | return REQUEST.RESPONSE.redirect(context.absolute_url() + \ |
---|
[681] | 22 | ('/academics_index?portal_status_message=%s' \ |
---|
[371] | 23 | % ('Courses cannot be renamed',))) |
---|
[681] | 24 | |
---|
[1724] | 25 | old_ids = REQUEST['ids'] |
---|
[370] | 26 | new_ids = REQUEST['new_ids'] |
---|
| 27 | new_ids = [id.upper() for id in REQUEST['new_ids']] |
---|
| 28 | |
---|
[586] | 29 | here = context |
---|
| 30 | if context.portal_type == "University": |
---|
| 31 | here = context.academics |
---|
[1724] | 32 | pt = context.portal_type |
---|
| 33 | mt = context.meta_type |
---|
| 34 | logger.info('%s starting renaming %s to %s' % (member,old_ids,new_ids)) |
---|
[370] | 35 | |
---|
[681] | 36 | here.manage_renameObjects(REQUEST['ids'], new_ids, REQUEST) |
---|
[1724] | 37 | if 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) |
---|
| 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)) |
---|
[681] | 68 | |
---|
[586] | 69 | return REQUEST.RESPONSE.redirect(here.absolute_url() + \ |
---|
| 70 | ('/academics_index?portal_status_message=%s' \ |
---|
[370] | 71 | % ('psm_item(s)_renamed',))) |
---|