| 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 | """ |
|---|
| 5 | try: |
|---|
| 6 | from Products.zdb import set_trace |
|---|
| 7 | except: |
|---|
| 8 | def set_trace(): |
|---|
| 9 | pass |
|---|
| 10 | |
|---|
| 11 | from urllib import urlencode |
|---|
| 12 | from Products.CPSDocument.utils import getFormUidUrlArg |
|---|
| 13 | if 'ajax_edit' in REQUEST.form: |
|---|
| 14 | return context.waeup_edit_ajax(REQUEST, cluster=cluster) |
|---|
| 15 | |
|---|
| 16 | import logging |
|---|
| 17 | logger = logging.getLogger('Skins.waeup_edit') |
|---|
| 18 | |
|---|
| 19 | mtool = context.portal_membership |
|---|
| 20 | member = mtool.getAuthenticatedMember() |
|---|
| 21 | doc = context.getContent() |
|---|
| 22 | |
|---|
| 23 | #if context.portal_type == "StudentStudyCourse": |
|---|
| 24 | # if len(context.objectIds()) > 0: |
|---|
| 25 | # psm = 'Edit of StudentStudyCourse is only possible if there are no levels inside!' |
|---|
| 26 | # args = getFormUidUrlArg(REQUEST) |
|---|
| 27 | # args['portal_status_message'] = psm |
|---|
| 28 | # url = context.absolute_url() + '?' + urlencode(args) |
|---|
| 29 | # return REQUEST.RESPONSE.redirect(url) |
|---|
| 30 | old_values = dict([(k,v) for k,v in doc.getDataModel().items()]) |
|---|
| 31 | |
|---|
| 32 | is_valid, ds = doc.validate(request=REQUEST, proxy=context, cluster=cluster, |
|---|
| 33 | use_session=True) |
|---|
| 34 | student_id = context.getStudentId() |
|---|
| 35 | action = "/" + came_from |
|---|
| 36 | if is_valid: |
|---|
| 37 | # comments = REQUEST.get('comments') |
|---|
| 38 | # context.cpsdocument_notify_modification(comments=comments) |
|---|
| 39 | if cpsdocument_edit_and_view_button is not None: |
|---|
| 40 | action = '' |
|---|
| 41 | new_values = dict([(k,v) for k,v in doc.getDataModel().items()]) |
|---|
| 42 | changed = [ k for k in old_values.keys() if new_values[k] != old_values[k]] |
|---|
| 43 | if student_id: |
|---|
| 44 | logger.info('%s edited %s object (fields %s) of %s' % (member, |
|---|
| 45 | |
|---|
| 46 | context.id, |
|---|
| 47 | ', '.join(changed), |
|---|
| 48 | student_id)) |
|---|
| 49 | else: |
|---|
| 50 | logger.info('%s edited %s %s (fields %s)' % (member, |
|---|
| 51 | context.portal_type, |
|---|
| 52 | context.id, |
|---|
| 53 | ', '.join(changed), |
|---|
| 54 | )) |
|---|
| 55 | |
|---|
| 56 | psm = 'psm_content_changed' |
|---|
| 57 | args = {} |
|---|
| 58 | else: |
|---|
| 59 | psm = 'psm_content_error' |
|---|
| 60 | args = getFormUidUrlArg(REQUEST) |
|---|
| 61 | |
|---|
| 62 | args['portal_status_message'] = psm |
|---|
| 63 | url = context.absolute_url() + action + '?' + urlencode(args) |
|---|
| 64 | REQUEST.RESPONSE.redirect(url) |
|---|
| 65 | |
|---|