source: WAeUP_SRP/base/skins/waeup_student/clearance_edit.py @ 2671

Last change on this file since 2671 was 2670, checked in by Henrik Bettermann, 17 years ago

further modifications for session change

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
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 2670 2007-11-15 22:07:14Z henrik $
10"""
11"""
12wftool = context.portal_workflow
13from urllib import urlencode
14from Products.CPSDocument.utils import getFormUidUrlArg
15import DateTime
16current = DateTime.DateTime()
17import logging
18logger = logging.getLogger('Skins.clearance_edit')
19request = REQUEST
20
21cpsdocument_edit_button = REQUEST.has_key('cpsdocument_edit_button')
22cpsdocument_edit_and_view_button = REQUEST.has_key('cpsdocument_edit_and_view_button')
23clear_and_validate_button = REQUEST.has_key('clear_and_validate_button')
24reject_clearance_button = REQUEST.has_key('reject_clearance_button')
25result_edit_button = REQUEST.has_key('result_edit_button')
26
27# Until ajax posts directly to its own script...
28##if 'ajax_edit' in REQUEST.form:
29##    return context.cpsdocument_edit_ajax(REQUEST, cluster=cluster)
30
31# Validate the document and write it if it's valid
32# (We don't call getEditableContent here, validate does it when needed.)
33wftool = context.portal_workflow
34info = context.getClearanceInfo()
35
36#'Sorry, you are not allowed to access this page!'
37if info == None:
38    return REQUEST.RESPONSE.redirect(context.standard_error_message())
39student = info['student']
40#app = info['app']
41#app_doc = info['app_doc']
42clear = info['clear']
43clear_doc = info['clear_doc']
44student_id = info['id']
45member_id = str(context.portal_membership.getAuthenticatedMember())
46result_widgets = ('fst_sit_results',
47                  'scd_sit_results',
48                  'alr_results',
49                  )
50required_scans = ('fst_sit_scan',
51#                 'jamb_slip',
52                  'ref_let',
53                  'acc_let'
54                 )
55form = request.form
56psm = ""
57args = {}
58action = "/external_clearance_edit_form"
59clearance_closed = False
60
61if context.isStudent():
62    action = "/clearance_edit_form"
63    if info['clear_review_state'] == 'closed':
64        clearance_closed = True
65
66if not clearance_closed:
67    is_valid, ds = clear_doc.validate(request=REQUEST,
68                                schema_id = 'student_clearance',
69                                layout_id = 'student_clearance',
70                                proxy=clear,
71                                use_session=False)
72if clear_and_validate_button and info['review_state'] == "clearance_requested":
73    logger.info('%s cleared %s' % (member_id,student_id ))
74    #from Products.zdb import set_trace
75    #set_trace()
76    clear_doc.edit(mapping = {'cleared_date': current,})
77    wftool.doActionFor(info['student'],'clear_and_validate')
78   
79    if info['per_review_state'] != 'opened':
80        wftool.doActionFor(info['per'],'open')
81   
82    per_doc = info['per'].getContent()
83    per_doc.edit(mapping = {'firstname': clear_doc.firstname, 'middlename': clear_doc.middlename, 'lastname': clear_doc.lastname,})
84   
85   
86   
87    psm = "Clearance and eligibility record is validated and student is cleared!"
88elif clear_and_validate_button and info['review_state'] == "cleared_and_validated":
89    psm = "This student is already cleared!"
90elif reject_clearance_button:
91    logger.info('%s rejected clearance for %s' % (member_id,student_id ))
92    try:
93        wftool.doActionFor(info['clear'],'open')
94    except:
95        return
96    wftool.doActionFor(info['student'],'reject_clearance')
97    action = "/external_contact_student_form"
98    psm = "Student's clearance request has been rejected! Please fill and submit the form below!"
99    subject = "Clearance request rejected"
100    args['subject'] = subject
101    args['continue'] = 'external_clearance_edit_form'
102elif clearance_closed:
103    action = "/clearance_view"
104    logger.info('%s tried to edit closed clearance object of %s' % (member_id,student_id ))
105elif is_valid:
106    if cpsdocument_edit_button or result_edit_button:
107        psm = "Content changed!"
108        logger.info('%s edited clearance object of %s' % (member_id,student_id ))
109    elif cpsdocument_edit_and_view_button:
110        if acknowledge and info['review_state'] == "clearance_pin_entered":
111            files = context.waeup_tool.picturesList()
112            req_found = [scan for scan in required_scans if scan in files]
113            birth_found = "age_dec" in files or "birth_certificate" in files
114            #if not req_found or not birth_found:
115            #    logger.info('%s requested clearance with documents missing' % (student_id))
116            #    psm = "You have not uploaded all necessary documents to request clearance!"
117            if not clear_doc.firstname or not clear_doc.lastname:
118                logger.info('%s requested clearance without confirming name' % (student_id))
119                psm = "Please fill the name fields! First and last name are required. "           
120            else:
121                logger.info('%s requested clearance' % (student_id))
122                clear_doc.edit(mapping = {'request_date': current,})
123                wftool.doActionFor(info['clear'],'close')
124                wftool.doActionFor(info['student'],'request_clearance',dest_container=1)
125                psm = "You successfully requested clearance!"
126                if context.isStudent():
127                    action = "/clearance_view"
128        elif acknowledge and info['review_state'] != "clearance_pin_entered":
129            logger.info('%s repeatedly requested clearance' % (student_id))
130            psm = "You have already requested clearance!"
131        else:
132            psm = "You must tick the acknowledgement check box before submission!"
133else:
134    psm = "Please correct your errors!"
135    args = getFormUidUrlArg(REQUEST)
136    logger.info('%s got error when editing the clearance object of %s' % (member_id,student_id))
137
138args['portal_status_message'] = psm
139url = clear.absolute_url() + action + '?' + urlencode(args)
140return REQUEST.RESPONSE.redirect(url)
141
Note: See TracBrowser for help on using the repository browser.