source: WAeUP_SRP/branches/joachim-azax-branch/skins/waeup_default/waeup_edit.py @ 2035

Last change on this file since 2035 was 1988, checked in by joachim, 17 years ago

merged r1979:r1987 from trunk

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