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