source: WAeUP_SRP/trunk/skins/waeup_student/clearance_edit.py @ 10559

Last change on this file since 10559 was 8538, checked in by Henrik Bettermann, 13 years ago

Do not overwrite names in personal data objects.

  • Property svn:keywords set to Id
File size: 6.9 KB
RevLine 
[1860]1## Script (Python) "clearance_edit"
[1107]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=
[805]9# $Id: clearance_edit.py 8538 2012-05-28 11:24:49Z henrik $
[788]10"""
11"""
12wftool = context.portal_workflow
13from urllib import urlencode
14from Products.CPSDocument.utils import getFormUidUrlArg
15import DateTime
16current = DateTime.DateTime()
[1016]17import logging
[1571]18logger = logging.getLogger('Skins.clearance_edit')
[1098]19request = REQUEST
[788]20
[885]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')
[1098]25result_edit_button = REQUEST.has_key('result_edit_button')
[893]26
[788]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.)
[832]33wftool = context.portal_workflow
[1073]34info = context.getClearanceInfo()
[788]35
[1036]36#'Sorry, you are not allowed to access this page!'
37if info == None:
[2364]38    return REQUEST.RESPONSE.redirect(context.standard_error_message())
[788]39student = info['student']
[1098]40#app = info['app']
41#app_doc = info['app_doc']
[788]42clear = info['clear']
43clear_doc = info['clear_doc']
[1016]44student_id = info['id']
45member_id = str(context.portal_membership.getAuthenticatedMember())
[1098]46result_widgets = ('fst_sit_results',
47                  'scd_sit_results',
48                  'alr_results',
49                  )
50required_scans = ('fst_sit_scan',
[1217]51#                 'jamb_slip',
[1101]52                  'ref_let',
[1098]53                  'acc_let'
[1860]54                 )
[3746]55# start customization
[2991]56
[3746]57no_scans_required = False
58
59# end customization       
60
[1098]61form = request.form
62psm = ""
63args = {}
64action = "/external_clearance_edit_form"
[1860]65clearance_closed = False
66
[1098]67if context.isStudent():
68    action = "/clearance_edit_form"
[1860]69    if info['clear_review_state'] == 'closed':
70        clearance_closed = True
[832]71
[1860]72if not clearance_closed:
73    is_valid, ds = clear_doc.validate(request=REQUEST,
[788]74                                schema_id = 'student_clearance',
[885]75                                layout_id = 'student_clearance',
[788]76                                proxy=clear,
[2373]77                                use_session=False)
[1839]78if clear_and_validate_button and info['review_state'] == "clearance_requested":
79    logger.info('%s cleared %s' % (member_id,student_id ))
80    #from Products.zdb import set_trace
81    #set_trace()
[3814]82    clear_doc.edit(mapping = {'clearance_officer': member_id,
83                              'cleared_date': current,})
[1839]84    wftool.doActionFor(info['student'],'clear_and_validate')
[8538]85    #if clear_doc.firstname and clear_doc.lastname:
86    #    if info['per_review_state'] != 'opened':
87    #        wftool.doActionFor(info['per'],'open')
88    #    per_doc = info['per'].getContent()
89    #    firstname = clear_doc.firstname.replace('-',' - ')
90    #    firstname = ' '.join([m.capitalize() for m in firstname.split()])
91    #    firstname = firstname.replace(' - ','-')
92    #    middlename = clear_doc.middlename.replace('-',' - ')
93    #    middlename = ' '.join([m.capitalize() for m in middlename.split()])
94    #    middlename = middlename.replace(' - ','-')
95    #    lastname = clear_doc.lastname.replace('-',' - ')
96    #    lastname = ' '.join([m.capitalize() for m in lastname.split()])
97    #    lastname = lastname.replace(' - ','-')
98    #    # we changed
99    #    context.waeup_tool.updateRoleMappingsFor('waeup_student_subobject_wf',info['per'])
100    #    per_doc.edit(mapping = {'firstname': firstname, 'middlename': middlename, 'lastname': lastname,})
[2672]101
[2013]102    psm = "Clearance and eligibility record is validated and student is cleared!"
[1839]103elif clear_and_validate_button and info['review_state'] == "cleared_and_validated":
104    psm = "This student is already cleared!"
105elif reject_clearance_button:
106    logger.info('%s rejected clearance for %s' % (member_id,student_id ))
[4065]107    clear_doc.edit(mapping = {'clearance_officer': '',
108                              'cleared_date': None,})   
[2491]109    try:
110        wftool.doActionFor(info['clear'],'open')
111    except:
[4065]112        pass
[1839]113    wftool.doActionFor(info['student'],'reject_clearance')
114    action = "/external_contact_student_form"
115    psm = "Student's clearance request has been rejected! Please fill and submit the form below!"
116    subject = "Clearance request rejected"
117    args['subject'] = subject
118    args['continue'] = 'external_clearance_edit_form'
[1860]119elif clearance_closed:
120    action = "/clearance_view"
[1862]121    logger.info('%s tried to edit closed clearance object of %s' % (member_id,student_id ))
[1839]122elif is_valid:
[1098]123    if cpsdocument_edit_button or result_edit_button:
[891]124        psm = "Content changed!"
[1996]125        logger.info('%s edited clearance object of %s' % (member_id,student_id ))
[851]126    elif cpsdocument_edit_and_view_button:
[1016]127        if acknowledge and info['review_state'] == "clearance_pin_entered":
[2364]128            files = context.waeup_tool.picturesList()
[2991]129            req_found = [scan for scan in required_scans if scan in files] or no_scans_required
130            birth_found = "age_dec" in files or "birth_certificate" in files or no_scans_required
[2673]131            if not req_found or not birth_found:
132                logger.info('%s requested clearance with documents missing' % (student_id))
133                psm = "You have not uploaded all necessary documents to request clearance!"
[5532]134            #elif not clear_doc.firstname or not clear_doc.lastname:
135            #    logger.info('%s requested clearance without confirming name' % (student_id))
136            #    psm = "Please fill the name fields! First and last name are required. "
[1098]137            else:
[1571]138                logger.info('%s requested clearance' % (student_id))
[2670]139                clear_doc.edit(mapping = {'request_date': current,})
[4550]140                try:
141                    wftool.doActionFor(info['clear'],'close')
142                except:
143                    logger.info("closing of clearance object of %s failed" % (student_id))
[1098]144                wftool.doActionFor(info['student'],'request_clearance',dest_container=1)
145                psm = "You successfully requested clearance!"
146                if context.isStudent():
147                    action = "/clearance_view"
[1016]148        elif acknowledge and info['review_state'] != "clearance_pin_entered":
[1571]149            logger.info('%s repeatedly requested clearance' % (student_id))
[1017]150            psm = "You have already requested clearance!"
[893]151        else:
152            psm = "You must tick the acknowledgement check box before submission!"
[851]153else:
[891]154    psm = "Please correct your errors!"
155    args = getFormUidUrlArg(REQUEST)
[1996]156    logger.info('%s got error when editing the clearance object of %s' % (member_id,student_id))
[891]157
[851]158args['portal_status_message'] = psm
[891]159url = clear.absolute_url() + action + '?' + urlencode(args)
[1575]160return REQUEST.RESPONSE.redirect(url)
[1106]161
Note: See TracBrowser for help on using the repository browser.