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