[859] | 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 |
---|
[2018] | 18 | if 'ajax_edit' in REQUEST.form: |
---|
| 19 | return context.waeup_edit_ajax(REQUEST, cluster=cluster) |
---|
[859] | 20 | |
---|
[1571] | 21 | import logging |
---|
| 22 | logger = logging.getLogger('Skins.waeup_edit') |
---|
| 23 | |
---|
| 24 | mtool = context.portal_membership |
---|
| 25 | member = mtool.getAuthenticatedMember() |
---|
| 26 | |
---|
[859] | 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.) |
---|
| 32 | doc = context.getContent() |
---|
[1025] | 33 | if context.portal_type == "StudentStudyCourse": |
---|
| 34 | if len(context.objectIds()) > 0: |
---|
[1571] | 35 | psm = 'Edit of StudentStudyCourse is only possible if there are no levels inside!' |
---|
[1025] | 36 | args = getFormUidUrlArg(REQUEST) |
---|
| 37 | args['portal_status_message'] = psm |
---|
| 38 | url = context.absolute_url() + '?' + urlencode(args) |
---|
| 39 | REQUEST.RESPONSE.redirect(url) |
---|
[1435] | 40 | |
---|
[859] | 41 | is_valid, ds = doc.validate(request=REQUEST, proxy=context, cluster=cluster, |
---|
| 42 | use_session=True) |
---|
| 43 | |
---|
[1840] | 44 | student_id = context.getStudentId() |
---|
| 45 | |
---|
[859] | 46 | ##if action is None: |
---|
| 47 | ## ti = doc.getTypeInfo() |
---|
| 48 | ## action = ti.queryMethodID('edit', 'external_edit_form') |
---|
| 49 | ## action = '/' + action |
---|
| 50 | |
---|
| 51 | action = "/" + came_from |
---|
| 52 | if is_valid: |
---|
| 53 | comments = REQUEST.get('comments') |
---|
| 54 | context.cpsdocument_notify_modification(comments=comments) |
---|
[1855] | 55 | |
---|
| 56 | ################################################### |
---|
[1744] | 57 | if False: |
---|
| 58 | if context.portal_type == "StudentStudyCourse": |
---|
| 59 | course = ds.get('study_course') |
---|
[1855] | 60 | #student_id = context.getStudentId() |
---|
[1744] | 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('/') |
---|
[1855] | 65 | #student_id = context.getStudentId() |
---|
[1744] | 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)) |
---|
[1840] | 74 | |
---|
[1744] | 75 | elif context.portal_type == "StudentApplication": # disabled |
---|
| 76 | entry_mode = ds.get('entry_mode') |
---|
[1855] | 77 | #student_id = context.getStudentId() |
---|
[1025] | 78 | context.students_catalog.modifyRecord(id = student_id, |
---|
[1744] | 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') |
---|
[1855] | 84 | #student_id = context.getStudentId() |
---|
[1744] | 85 | context.students_catalog.modifyRecord(id = student_id, |
---|
| 86 | matric_no = matric_no, |
---|
| 87 | ) |
---|
[1840] | 88 | logger.info('%s edited %s of %s' % (member,context.id,student_id)) |
---|
[1744] | 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') |
---|
[1855] | 95 | #student_id = context.getStudentId() |
---|
[1744] | 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) |
---|
[1855] | 118 | ################################################### |
---|
| 119 | |
---|
| 120 | |
---|
[859] | 121 | if cpsdocument_edit_and_view_button is not None: |
---|
| 122 | action = '' |
---|
| 123 | psm = 'psm_content_changed' |
---|
| 124 | args = {} |
---|
| 125 | else: |
---|
| 126 | psm = 'psm_content_error' |
---|
| 127 | args = getFormUidUrlArg(REQUEST) |
---|
| 128 | |
---|
[1855] | 129 | logger.info('%s edited %s %s of %s' % (member,context.portal_type,context.id,student_id)) |
---|
[859] | 130 | args['portal_status_message'] = psm |
---|
| 131 | url = context.absolute_url() + action + '?' + urlencode(args) |
---|
| 132 | REQUEST.RESPONSE.redirect(url) |
---|
| 133 | |
---|