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

Last change on this file since 16651 was 5225, checked in by Henrik Bettermann, 14 years ago

courses_catalog need not to be updated, this is done by the event service.

Fix update of students_catalog after renaming of faculty ids.

  • Property svn:keywords set to Id
File size: 2.4 KB
RevLine 
[370]1##parameters=
[486]2# $Id: id_rename.py 5225 2010-06-18 17:29:56Z henrik $
[370]3"""
4Rename objects which ids are passed in the request.
5
6Used within the folder_contents template.
7"""
[1724]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()
[370]17
18REQUEST = context.REQUEST
19
[371]20if 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]25old_ids = REQUEST['ids']
[370]26new_ids = REQUEST['new_ids']
[2027]27#new_ids = [id.upper() for id in REQUEST['new_ids']]
[370]28
[586]29here = context
30if context.portal_type == "University":
31    here = context.academics
[1724]32pt = context.portal_type
33mt = context.meta_type
[2743]34logger.info('%s started renaming %s to %s' % (member,old_ids,new_ids))
[370]35
[681]36here.manage_renameObjects(REQUEST['ids'], new_ids, REQUEST)
[5225]37if pt == 'AcademicsFolder':
[1724]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)]
[2027]43        data['faculty'] = new_fid
[1724]44        for sid in student_ids:
45            data['id'] = sid
46            context.students_catalog.modifyRecord(**data)
[5225]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)
[1724]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)
[5225]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)
[1724]67logger.info('%s finished renaming %s to %s' % (member,old_ids,new_ids))
[681]68
[586]69return REQUEST.RESPONSE.redirect(here.absolute_url() + \
[2027]70                                ('?portal_status_message=%s' \
[370]71                                % ('psm_item(s)_renamed',)))
Note: See TracBrowser for help on using the repository browser.