source: WAeUP_SRP/base/skins/waeup_default/waeup_edit.py @ 2284

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

disable ajax because it does not work on the live system

also, it does not write any logging message

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