1 | ## Script (Python) "clearance_edit" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=REQUEST, acknowledge=None |
---|
8 | ##title= |
---|
9 | # $Id: clearance_edit.py 1017 2006-12-08 21:12:01Z henrik $ |
---|
10 | """ |
---|
11 | """ |
---|
12 | wftool = context.portal_workflow |
---|
13 | from urllib import urlencode |
---|
14 | from Products.CPSDocument.utils import getFormUidUrlArg |
---|
15 | import DateTime |
---|
16 | current = DateTime.DateTime() |
---|
17 | import logging |
---|
18 | logger = logging.getLogger('Student.Clearance') |
---|
19 | |
---|
20 | cpsdocument_edit_button = REQUEST.has_key('cpsdocument_edit_button') |
---|
21 | cpsdocument_edit_and_view_button = REQUEST.has_key('cpsdocument_edit_and_view_button') |
---|
22 | clear_and_validate_button = REQUEST.has_key('clear_and_validate_button') |
---|
23 | reject_clearance_button = REQUEST.has_key('reject_clearance_button') |
---|
24 | |
---|
25 | # Until ajax posts directly to its own script... |
---|
26 | ##if 'ajax_edit' in REQUEST.form: |
---|
27 | ## return context.cpsdocument_edit_ajax(REQUEST, cluster=cluster) |
---|
28 | |
---|
29 | # Validate the document and write it if it's valid |
---|
30 | # (We don't call getEditableContent here, validate does it when needed.) |
---|
31 | wftool = context.portal_workflow |
---|
32 | info = context.getStudentInfo() |
---|
33 | |
---|
34 | student = info['student'] |
---|
35 | app = info['app'] |
---|
36 | app_doc = info['app_doc'] |
---|
37 | clear = info['clear'] |
---|
38 | clear_doc = info['clear_doc'] |
---|
39 | student_id = info['id'] |
---|
40 | member_id = str(context.portal_membership.getAuthenticatedMember()) |
---|
41 | |
---|
42 | is_valid, ds = clear_doc.validate(request=REQUEST, |
---|
43 | schema_id = 'student_clearance', |
---|
44 | layout_id = 'student_clearance', |
---|
45 | proxy=clear, |
---|
46 | use_session=True) |
---|
47 | |
---|
48 | psm = "" |
---|
49 | args = {} |
---|
50 | action = "/external_clearance_edit_form" |
---|
51 | if is_valid: |
---|
52 | if cpsdocument_edit_button: |
---|
53 | psm = "Content changed!" |
---|
54 | if context.isStudent(): |
---|
55 | action = "/clearance_edit_form" |
---|
56 | elif cpsdocument_edit_and_view_button: |
---|
57 | if acknowledge and info['review_state'] == "clearance_pin_entered": |
---|
58 | logger.info('"%s","requested clearance"' % (student_id)) |
---|
59 | info['clear_doc'].edit(mapping = {'request_date': current,}) |
---|
60 | wftool.doActionFor(info['clear'],'close') |
---|
61 | wftool.doActionFor(info['student'],'request_clearance',dest_container=1) |
---|
62 | psm = "You successfully requested clearance!" |
---|
63 | if context.isStudent(): |
---|
64 | action = "/clearance_view" |
---|
65 | elif acknowledge and info['review_state'] != "clearance_pin_entered": |
---|
66 | logger.info('"%s","repeatedly requested clearance"' % (student_id)) |
---|
67 | psm = "You have already requested clearance!" |
---|
68 | if context.isStudent(): |
---|
69 | action = "/clearance_edit_form" |
---|
70 | else: |
---|
71 | psm = "You must tick the acknowledgement check box before submission!" |
---|
72 | if context.isStudent(): |
---|
73 | action = "/clearance_edit_form" |
---|
74 | elif clear_and_validate_button and info['review_state'] == "clearance_requested": |
---|
75 | logger.info('"%s","cleared","%s"' % (member_id,student_id )) |
---|
76 | wftool.doActionFor(info['student'],'clear_and_validate') |
---|
77 | info['clear_doc'].edit(mapping = {'cleared_date': current,}) |
---|
78 | psm = "Clearance and eligibility record is validated and and student is cleared!" |
---|
79 | elif clear_and_validate_button and info['review_state'] == "cleared_and_validated": |
---|
80 | psm = "This student is already cleared!" |
---|
81 | elif reject_clearance_button: |
---|
82 | logger.info('"%s","rejected clearance for","%s"' % (member_id,student_id )) |
---|
83 | wftool.doActionFor(info['clear'],'open') |
---|
84 | wftool.doActionFor(info['student'],'reject_clearance') |
---|
85 | action = "/contact_student_form" |
---|
86 | psm = "Student's clearance request has been rejected! Please fill and submit the form below!" |
---|
87 | else: |
---|
88 | psm = "Please correct your errors!" |
---|
89 | args = getFormUidUrlArg(REQUEST) |
---|
90 | |
---|
91 | args['portal_status_message'] = psm |
---|
92 | url = clear.absolute_url() + action + '?' + urlencode(args) |
---|
93 | REQUEST.RESPONSE.redirect(url) |
---|