source: WAeUP_SRP/trunk/skins/waeup_default/waeup_edit.py @ 1855

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

log which object type is edited

File size: 5.5 KB
Line 
1##parameters=REQUEST, cluster=None, cpsdocument_edit_and_view_button=None, came_from=None
2# $Id: external_edit.py 805 2006-11-09 09:38:29Z joachim $
3"""
4Called when a document form is posted.
5
6Validates data, then:
7
8 - if there's no error, updates the object and redirects to it,
9
10 - if there's an error, puts data in session and redirects to edit form.
11
12A form uid is propagated during the redirect to uniquely identify the
13form in the session.
14"""
15
16from urllib import urlencode
17from Products.CPSDocument.utils import getFormUidUrlArg
18
19import logging
20logger = logging.getLogger('Skins.waeup_edit')
21
22mtool = context.portal_membership
23member = mtool.getAuthenticatedMember()
24
25# Check flexible controls
26#context.editLayouts(REQUEST=REQUEST)
27
28# Validate the document and write it if it's valid
29# (We don't call getEditableContent here, validate does it when needed.)
30doc = context.getContent()
31if context.portal_type == "StudentStudyCourse":
32    if len(context.objectIds()) > 0:
33        psm = 'Edit of StudentStudyCourse is only possible if there are no levels inside!'
34        args = getFormUidUrlArg(REQUEST)
35        args['portal_status_message'] = psm
36        url = context.absolute_url() + '?' + urlencode(args)
37        REQUEST.RESPONSE.redirect(url)
38
39is_valid, ds = doc.validate(request=REQUEST, proxy=context, cluster=cluster,
40                            use_session=True)
41
42student_id = context.getStudentId()
43
44##if action is None:
45##    ti = doc.getTypeInfo()
46##    action = ti.queryMethodID('edit', 'external_edit_form')
47##    action = '/' + action
48
49action = "/" + came_from
50if is_valid:
51    comments = REQUEST.get('comments')
52    context.cpsdocument_notify_modification(comments=comments)
53
54    ###################################################
55    if False:
56        if context.portal_type == "StudentStudyCourse":
57            course = ds.get('study_course')
58            #student_id = context.getStudentId()
59            res = context.portal_catalog(portal_type='Certificate',id = course)
60            if res:
61                c_brain = res[0]
62                c_path = c_brain.getPath().split('/')
63                #student_id = context.getStudentId()
64                context.students_catalog.modifyRecord(id = student_id,
65                                                      course = course,
66                                                      level = ds.get('current_level'),
67                                                      verdict = ds.get('current_verdict'),
68                                                      faculty = c_path[-4],
69                                                      department = c_path[-3],
70                                                      )
71                logger.info('%s edited %s (%s) of %s' % (member,context.id,course,student_id))
72
73        elif context.portal_type == "StudentApplication": # disabled
74            entry_mode = ds.get('entry_mode')
75            #student_id = context.getStudentId()
76            context.students_catalog.modifyRecord(id = student_id,
77                                                  entry_mode = entry_mode,
78                                                 )
79            logger.info('%s edited %s of %s' % (member,context.id,student_id))
80        elif context.portal_type == "StudentClearance":
81            matric_no = ds.get('matric_no')
82            #student_id = context.getStudentId()
83            context.students_catalog.modifyRecord(id = student_id,
84                                                  matric_no = matric_no,
85                                                 )
86            logger.info('%s edited %s of %s' % (member,context.id,student_id))
87        elif context.portal_type in ("StudentPersonal",):
88            name = "%(firstname)s %(middlename)s %(lastname)s" % ds
89            name = name.strip()
90            name = name.replace('  ',' ')
91            email = ds.get('email')
92            phone = ds.get('phone')
93            #student_id = context.getStudentId()
94            #app_doc = context.application.getContent()
95            #jamb_sex = 'M'
96            #if ds.get('sex'):
97            #    jamb_sex = 'F'
98            # originally imported data must be kept; app_doc should not be changed here
99            #app_doc.edit(mapping={'jamb_lastname': name,
100            #                      'jamb_sex': jamb_sex
101            #                      })
102            context.students_catalog.modifyRecord(id = student_id,
103                                                  name = name,
104                                                  email = email,
105                                                  phone = phone,
106                                                  sex = ds.get('sex'),
107                                                 )
108            logger.info('%s edited %s of %s' % (member,context.id,student_id))
109        elif context.portal_type == "xxxxCourse": # disabled handled by events
110            dd = {}
111            dd.update(ds) # ds is not a real dictionary
112            try:
113                context.courses_catalog.modifyRecord(**dd)
114            except KeyError:
115                context.courses_catalog.addRecord(**dd)
116    ###################################################
117   
118   
119    if cpsdocument_edit_and_view_button is not None:
120        action = ''
121    psm = 'psm_content_changed'
122    args = {}
123else:
124    psm = 'psm_content_error'
125    args = getFormUidUrlArg(REQUEST)
126
127logger.info('%s edited %s %s of %s' % (member,context.portal_type,context.id,student_id))
128args['portal_status_message'] = psm
129url = context.absolute_url() + action + '?' + urlencode(args)
130REQUEST.RESPONSE.redirect(url)
131
Note: See TracBrowser for help on using the repository browser.