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 1054 2006-12-14 07:32:31Z 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 | |
---|
35 | #'Sorry, you are not allowed to access this page!' |
---|
36 | if info == None: |
---|
37 | #return REQUEST.RESPONSE.redirect(context.portal_url()) |
---|
38 | return REQUEST.RESPONSE.redirect(context.standard_error_message()) |
---|
39 | |
---|
40 | |
---|
41 | student = info['student'] |
---|
42 | app = info['app'] |
---|
43 | app_doc = info['app_doc'] |
---|
44 | clear = info['clear'] |
---|
45 | clear_doc = info['clear_doc'] |
---|
46 | student_id = info['id'] |
---|
47 | member_id = str(context.portal_membership.getAuthenticatedMember()) |
---|
48 | |
---|
49 | is_valid, ds = clear_doc.validate(request=REQUEST, |
---|
50 | schema_id = 'student_clearance', |
---|
51 | layout_id = 'student_clearance', |
---|
52 | proxy=clear, |
---|
53 | use_session=True) |
---|
54 | |
---|
55 | psm = "" |
---|
56 | args = {} |
---|
57 | action = "/external_clearance_edit_form" |
---|
58 | if context.isStudent(): |
---|
59 | action = "/clearance_edit_form" |
---|
60 | |
---|
61 | if is_valid: |
---|
62 | if cpsdocument_edit_button: |
---|
63 | psm = "Content changed!" |
---|
64 | logger.info('"%s","edited clearance of","%s"' % (member_id,student_id )) |
---|
65 | if clear_doc.clr_ac_pin == "": |
---|
66 | res = context.portal_pins(student=member_id) |
---|
67 | if res: |
---|
68 | p = res[0].pin |
---|
69 | if len(p) > 10: |
---|
70 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
71 | else: |
---|
72 | pin = p |
---|
73 | clear_doc.edit(mapping={'clr_ac_pin': pin}) |
---|
74 | elif cpsdocument_edit_and_view_button: |
---|
75 | if acknowledge and info['review_state'] == "clearance_pin_entered": |
---|
76 | logger.info('"%s","requested clearance"' % (student_id)) |
---|
77 | info['clear_doc'].edit(mapping = {'request_date': current,}) |
---|
78 | wftool.doActionFor(info['clear'],'close') |
---|
79 | wftool.doActionFor(info['student'],'request_clearance',dest_container=1) |
---|
80 | psm = "You successfully requested clearance!" |
---|
81 | if context.isStudent(): |
---|
82 | action = "/clearance_view" |
---|
83 | elif acknowledge and info['review_state'] != "clearance_pin_entered": |
---|
84 | logger.info('"%s","repeatedly requested clearance"' % (student_id)) |
---|
85 | psm = "You have already requested clearance!" |
---|
86 | else: |
---|
87 | psm = "You must tick the acknowledgement check box before submission!" |
---|
88 | elif clear_and_validate_button and info['review_state'] == "clearance_requested": |
---|
89 | logger.info('"%s","cleared","%s"' % (member_id,student_id )) |
---|
90 | #from Products.zdb import set_trace |
---|
91 | #set_trace() |
---|
92 | info['clear_doc'].edit(mapping = {'cleared_date': current,}) |
---|
93 | wftool.doActionFor(info['student'],'clear_and_validate') |
---|
94 | psm = "Clearance and eligibility record is validated and and student is cleared!" |
---|
95 | elif clear_and_validate_button and info['review_state'] == "cleared_and_validated": |
---|
96 | psm = "This student is already cleared!" |
---|
97 | elif reject_clearance_button: |
---|
98 | logger.info('"%s","rejected clearance for","%s"' % (member_id,student_id )) |
---|
99 | wftool.doActionFor(info['clear'],'open') |
---|
100 | wftool.doActionFor(info['student'],'reject_clearance') |
---|
101 | action = "/contact_student_form" |
---|
102 | psm = "Student's clearance request has been rejected! Please fill and submit the form below!" |
---|
103 | else: |
---|
104 | psm = "Please correct your errors!" |
---|
105 | args = getFormUidUrlArg(REQUEST) |
---|
106 | |
---|
107 | args['portal_status_message'] = psm |
---|
108 | url = clear.absolute_url() + action + '?' + urlencode(args) |
---|
109 | REQUEST.RESPONSE.redirect(url) |
---|