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

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

also birth certificate is not required

  • Property svn:keywords set to Id
File size: 6.5 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 2991 2008-01-08 10:09:06Z 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                 )
55no_scans_required = context.portal_url().find('fceokene') > -1                 
56
57form = request.form
58psm = ""
59args = {}
60action = "/external_clearance_edit_form"
61clearance_closed = False
62
63if context.isStudent():
64    action = "/clearance_edit_form"
65    if info['clear_review_state'] == 'closed':
66        clearance_closed = True
67
68if not clearance_closed:
69    is_valid, ds = clear_doc.validate(request=REQUEST,
70                                schema_id = 'student_clearance',
71                                layout_id = 'student_clearance',
72                                proxy=clear,
73                                use_session=False)
74if clear_and_validate_button and info['review_state'] == "clearance_requested":
75    logger.info('%s cleared %s' % (member_id,student_id ))
76    #from Products.zdb import set_trace
77    #set_trace()
78    clear_doc.edit(mapping = {'cleared_date': current,})
79    wftool.doActionFor(info['student'],'clear_and_validate')
80
81
82    if clear_doc.firstname and clear_doc.lastname:
83        if info['per_review_state'] != 'opened':
84            wftool.doActionFor(info['per'],'open')
85        per_doc = info['per'].getContent()
86        firstname = clear_doc.firstname.replace('-',' - ')
87        firstname = ' '.join([m.capitalize() for m in firstname.split()])
88        firstname = firstname.replace(' - ','-')
89        middlename = clear_doc.middlename.replace('-',' - ')
90        middlename = ' '.join([m.capitalize() for m in middlename.split()])
91        middlename = middlename.replace(' - ','-')
92        lastname = clear_doc.lastname.replace('-',' - ')
93        lastname = ' '.join([m.capitalize() for m in lastname.split()])
94        lastname = lastname.replace(' - ','-')
95        # we changed
96        context.waeup_tool.updateRoleMappingsFor('waeup_student_subobject_wf',info['per'])
97        per_doc.edit(mapping = {'firstname': firstname, 'middlename': middlename, 'lastname': lastname,})
98
99    psm = "Clearance and eligibility record is validated and student is cleared!"
100elif clear_and_validate_button and info['review_state'] == "cleared_and_validated":
101    psm = "This student is already cleared!"
102elif reject_clearance_button:
103    logger.info('%s rejected clearance for %s' % (member_id,student_id ))
104    try:
105        wftool.doActionFor(info['clear'],'open')
106    except:
107        return
108    wftool.doActionFor(info['student'],'reject_clearance')
109    action = "/external_contact_student_form"
110    psm = "Student's clearance request has been rejected! Please fill and submit the form below!"
111    subject = "Clearance request rejected"
112    args['subject'] = subject
113    args['continue'] = 'external_clearance_edit_form'
114elif clearance_closed:
115    action = "/clearance_view"
116    logger.info('%s tried to edit closed clearance object of %s' % (member_id,student_id ))
117elif is_valid:
118    if cpsdocument_edit_button or result_edit_button:
119        psm = "Content changed!"
120        logger.info('%s edited clearance object of %s' % (member_id,student_id ))
121    elif cpsdocument_edit_and_view_button:
122        if acknowledge and info['review_state'] == "clearance_pin_entered":
123            files = context.waeup_tool.picturesList()
124            req_found = [scan for scan in required_scans if scan in files] or no_scans_required
125            birth_found = "age_dec" in files or "birth_certificate" in files or no_scans_required
126            if not req_found or not birth_found:
127                logger.info('%s requested clearance with documents missing' % (student_id))
128                psm = "You have not uploaded all necessary documents to request clearance!"
129            elif not clear_doc.firstname or not clear_doc.lastname:
130                logger.info('%s requested clearance without confirming name' % (student_id))
131                psm = "Please fill the name fields! First and last name are required. "
132            else:
133                logger.info('%s requested clearance' % (student_id))
134                clear_doc.edit(mapping = {'request_date': current,})
135                wftool.doActionFor(info['clear'],'close')
136                wftool.doActionFor(info['student'],'request_clearance',dest_container=1)
137                psm = "You successfully requested clearance!"
138                if context.isStudent():
139                    action = "/clearance_view"
140        elif acknowledge and info['review_state'] != "clearance_pin_entered":
141            logger.info('%s repeatedly requested clearance' % (student_id))
142            psm = "You have already requested clearance!"
143        else:
144            psm = "You must tick the acknowledgement check box before submission!"
145else:
146    psm = "Please correct your errors!"
147    args = getFormUidUrlArg(REQUEST)
148    logger.info('%s got error when editing the clearance object of %s' % (member_id,student_id))
149
150args['portal_status_message'] = psm
151url = clear.absolute_url() + action + '?' + urlencode(args)
152return REQUEST.RESPONSE.redirect(url)
153
Note: See TracBrowser for help on using the repository browser.