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 | logger.info('%s edited %s %s (%s) of %s' % (member, |
---|
44 | context.portal_type, |
---|
45 | context.id, |
---|
46 | ','.join(changed), |
---|
47 | student_id)) |
---|
48 | psm = 'psm_content_changed' |
---|
49 | args = {} |
---|
50 | else: |
---|
51 | psm = 'psm_content_error' |
---|
52 | args = getFormUidUrlArg(REQUEST) |
---|
53 | |
---|
54 | args['portal_status_message'] = psm |
---|
55 | url = context.absolute_url() + action + '?' + urlencode(args) |
---|
56 | REQUEST.RESPONSE.redirect(url) |
---|
57 | |
---|