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 | """ |
---|
4 | Called when a document form is posted. |
---|
5 | |
---|
6 | Validates 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 | |
---|
12 | A form uid is propagated during the redirect to uniquely identify the |
---|
13 | form in the session. |
---|
14 | """ |
---|
15 | |
---|
16 | from urllib import urlencode |
---|
17 | from Products.CPSDocument.utils import getFormUidUrlArg |
---|
18 | |
---|
19 | # Check flexible controls |
---|
20 | #context.editLayouts(REQUEST=REQUEST) |
---|
21 | |
---|
22 | # Validate the document and write it if it's valid |
---|
23 | # (We don't call getEditableContent here, validate does it when needed.) |
---|
24 | doc = context.getContent() |
---|
25 | if context.portal_type == "StudentStudyCourse": |
---|
26 | if len(context.objectIds()) > 0: |
---|
27 | psm = 'Edit of StudyCourse is only possible if there are no levels' |
---|
28 | args = getFormUidUrlArg(REQUEST) |
---|
29 | args['portal_status_message'] = psm |
---|
30 | url = context.absolute_url() + '?' + urlencode(args) |
---|
31 | REQUEST.RESPONSE.redirect(url) |
---|
32 | |
---|
33 | is_valid, ds = doc.validate(request=REQUEST, proxy=context, cluster=cluster, |
---|
34 | use_session=True) |
---|
35 | |
---|
36 | ##if action is None: |
---|
37 | ## ti = doc.getTypeInfo() |
---|
38 | ## action = ti.queryMethodID('edit', 'external_edit_form') |
---|
39 | ## action = '/' + action |
---|
40 | |
---|
41 | action = "/" + came_from |
---|
42 | if is_valid: |
---|
43 | comments = REQUEST.get('comments') |
---|
44 | context.cpsdocument_notify_modification(comments=comments) |
---|
45 | if context.portal_type == "StudentStudyCourse": |
---|
46 | course = ds.get('study_course') |
---|
47 | student_id = context.getStudentId() |
---|
48 | res = context.portal_catalog(portal_type='Certificate',id = course) |
---|
49 | if res: |
---|
50 | c_brain = res[0] |
---|
51 | c_path = c_brain.getPath().split('/') |
---|
52 | student_id = context.getStudentId() |
---|
53 | context.students_catalog.modifyRecord(id = student_id, |
---|
54 | course = course, |
---|
55 | level = ds.get('current_level'), |
---|
56 | verdict = ds.get('current_verdict'), |
---|
57 | faculty = c_path[-4], |
---|
58 | department = c_path[-3], |
---|
59 | ) |
---|
60 | elif context.portal_type == "StudentApplication": |
---|
61 | entry_mode = ds.get('entry_mode') |
---|
62 | student_id = context.getStudentId() |
---|
63 | context.students_catalog.modifyRecord(id = student_id, |
---|
64 | entry_mode = entry_mode, |
---|
65 | ) |
---|
66 | elif context.portal_type == "StudentClearance": |
---|
67 | matric_no = ds.get('matric_no') |
---|
68 | student_id = context.getStudentId() |
---|
69 | context.students_catalog.modifyRecord(id = student_id, |
---|
70 | matric_no = matric_no, |
---|
71 | ) |
---|
72 | elif context.portal_type in ("StudentPersonal",): |
---|
73 | name = "%(firstname)s %(middlename)s %(lastname)s" % ds |
---|
74 | name = name.strip() |
---|
75 | name = name.replace(' ',' ') |
---|
76 | email = ds.get('email') |
---|
77 | phone = ds.get('phone') |
---|
78 | student_id = context.getStudentId() |
---|
79 | app_doc = context.application.getContent() |
---|
80 | jamb_sex = 'M' |
---|
81 | if ds.get('sex'): |
---|
82 | jamb_sex = 'F' |
---|
83 | app_doc.edit(mapping={'jamb_lastname': name, |
---|
84 | 'jamb_sex': jamb_sex |
---|
85 | }) |
---|
86 | context.students_catalog.modifyRecord(id = student_id, |
---|
87 | name = name, |
---|
88 | email = email, |
---|
89 | phone = phone, |
---|
90 | sex = ds.get('sex'), |
---|
91 | ) |
---|
92 | elif context.portal_type == "Course": |
---|
93 | dd = {} |
---|
94 | dd.update(ds) # ds is not a real dictionary |
---|
95 | try: |
---|
96 | context.courses_catalog.modifyRecord(**dd) |
---|
97 | except KeyError: |
---|
98 | context.courses_catalog.addRecord(**dd) |
---|
99 | if cpsdocument_edit_and_view_button is not None: |
---|
100 | action = '' |
---|
101 | psm = 'psm_content_changed' |
---|
102 | args = {} |
---|
103 | else: |
---|
104 | psm = 'psm_content_error' |
---|
105 | args = getFormUidUrlArg(REQUEST) |
---|
106 | |
---|
107 | args['portal_status_message'] = psm |
---|
108 | url = context.absolute_url() + action + '?' + urlencode(args) |
---|
109 | REQUEST.RESPONSE.redirect(url) |
---|
110 | |
---|