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