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

Last change on this file since 1764 was 1744, checked in by joachim, 18 years ago

disable editing of students_catalog

File size: 5.3 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
42##if action is None:
43##    ti = doc.getTypeInfo()
44##    action = ti.queryMethodID('edit', 'external_edit_form')
45##    action = '/' + action
46
47action = "/" + came_from
48if is_valid:
49    comments = REQUEST.get('comments')
50    context.cpsdocument_notify_modification(comments=comments)
51    if False:
52        if context.portal_type == "StudentStudyCourse":
53            course = ds.get('study_course')
54            student_id = context.getStudentId()
55            res = context.portal_catalog(portal_type='Certificate',id = course)
56            if res:
57                c_brain = res[0]
58                c_path = c_brain.getPath().split('/')
59                student_id = context.getStudentId()
60                context.students_catalog.modifyRecord(id = student_id,
61                                                      course = course,
62                                                      level = ds.get('current_level'),
63                                                      verdict = ds.get('current_verdict'),
64                                                      faculty = c_path[-4],
65                                                      department = c_path[-3],
66                                                      )
67                logger.info('%s edited %s (%s) of %s' % (member,context.id,course,student_id))
68   
69        elif context.portal_type == "StudentApplication": # disabled
70            entry_mode = ds.get('entry_mode')
71            student_id = context.getStudentId()
72            context.students_catalog.modifyRecord(id = student_id,
73                                                  entry_mode = entry_mode,
74                                                 )
75            logger.info('%s edited %s of %s' % (member,context.id,student_id))
76        elif context.portal_type == "StudentClearance":
77            matric_no = ds.get('matric_no')
78            student_id = context.getStudentId()
79            context.students_catalog.modifyRecord(id = student_id,
80                                                  matric_no = matric_no,
81                                                 )
82            logger.info('%s edited %s of %s' % (member,context.id,student_id))                                             
83        elif context.portal_type in ("StudentPersonal",):
84            name = "%(firstname)s %(middlename)s %(lastname)s" % ds
85            name = name.strip()
86            name = name.replace('  ',' ')
87            email = ds.get('email')
88            phone = ds.get('phone')
89            student_id = context.getStudentId()
90            #app_doc = context.application.getContent()
91            #jamb_sex = 'M'
92            #if ds.get('sex'):
93            #    jamb_sex = 'F'
94            # originally imported data must be kept; app_doc should not be changed here
95            #app_doc.edit(mapping={'jamb_lastname': name,
96            #                      'jamb_sex': jamb_sex
97            #                      })
98            context.students_catalog.modifyRecord(id = student_id,
99                                                  name = name,
100                                                  email = email,
101                                                  phone = phone,
102                                                  sex = ds.get('sex'),
103                                                 )
104            logger.info('%s edited %s of %s' % (member,context.id,student_id))
105        elif context.portal_type == "xxxxCourse": # disabled handled by events
106            dd = {}
107            dd.update(ds) # ds is not a real dictionary
108            try:
109                context.courses_catalog.modifyRecord(**dd)
110            except KeyError:
111                context.courses_catalog.addRecord(**dd)
112    if cpsdocument_edit_and_view_button is not None:
113        action = ''
114    psm = 'psm_content_changed'
115    args = {}
116else:
117    psm = 'psm_content_error'
118    args = getFormUidUrlArg(REQUEST)
119
120args['portal_status_message'] = psm
121url = context.absolute_url() + action + '?' + urlencode(args)
122REQUEST.RESPONSE.redirect(url)
123
Note: See TracBrowser for help on using the repository browser.