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

Last change on this file since 1959 was 1862, checked in by Henrik Bettermann, 18 years ago

ticket #216 closed

  • Property svn:keywords set to Id
File size: 5.6 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 1862 2007-06-07 20:41:51Z 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:
[1073]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                 )
[1098]55form = request.form
56psm = ""
57args = {}
58action = "/external_clearance_edit_form"
[1860]59clearance_closed = False
60
[1098]61if context.isStudent():
62    action = "/clearance_edit_form"
[1860]63    if info['clear_review_state'] == 'closed':
64        clearance_closed = True
[832]65
[1860]66if not clearance_closed:
67    is_valid, ds = clear_doc.validate(request=REQUEST,
[788]68                                schema_id = 'student_clearance',
[885]69                                layout_id = 'student_clearance',
[788]70                                proxy=clear,
71                                use_session=True)
[1839]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    info['clear_doc'].edit(mapping = {'cleared_date': current,})
77    wftool.doActionFor(info['student'],'clear_and_validate')
78    psm = "Clearance and eligibility record is validated and and student is cleared!"
79elif clear_and_validate_button and info['review_state'] == "cleared_and_validated":
80    psm = "This student is already cleared!"
81elif 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 = "/external_contact_student_form"
86    psm = "Student's clearance request has been rejected! Please fill and submit the form below!"
87    subject = "Clearance request rejected"
88    args['subject'] = subject
89    args['continue'] = 'external_clearance_edit_form'
[1860]90elif clearance_closed:
91    action = "/clearance_view"
[1862]92    logger.info('%s tried to edit closed clearance object of %s' % (member_id,student_id ))
[1839]93elif is_valid:
[1098]94    if cpsdocument_edit_button or result_edit_button:
[891]95        psm = "Content changed!"
[1571]96        logger.info('%s edited clearance of %s' % (member_id,student_id ))
[1027]97        if clear_doc.clr_ac_pin == "":
98            res = context.portal_pins(student=member_id)
99            if res:
100                p = res[0].pin
101                if len(p) > 10:
102                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
103                else:
104                    pin = p
105                clear_doc.edit(mapping={'clr_ac_pin': pin})
[851]106    elif cpsdocument_edit_and_view_button:
[1016]107        if acknowledge and info['review_state'] == "clearance_pin_entered":
[1098]108            missing = False
[1110]109            files = clear_doc.objectIds()
[1098]110            for scan in required_scans:
[1110]111                if scan not in files:
[1098]112                    missing = True
113                    break
114            if not missing:
[1110]115                if not "age_dec" in files and not "birth_certificate" in files:
[1098]116                    missing = True
117            if missing:
[1571]118                logger.info('%s requested clearance with documents missing' % (student_id))
[1106]119                psm = "You have not uploaded all necessary documents to request clearance!"
[1098]120            else:
[1571]121                logger.info('%s requested clearance' % (student_id))
[1098]122                info['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"
[1016]128        elif acknowledge and info['review_state'] != "clearance_pin_entered":
[1571]129            logger.info('%s repeatedly requested clearance' % (student_id))
[1017]130            psm = "You have already requested clearance!"
[893]131        else:
132            psm = "You must tick the acknowledgement check box before submission!"
[851]133else:
[891]134    psm = "Please correct your errors!"
135    args = getFormUidUrlArg(REQUEST)
[1837]136    logger.info('%s got error when editing %s' % (member_id,student_id))
[891]137
[851]138args['portal_status_message'] = psm
[891]139url = clear.absolute_url() + action + '?' + urlencode(args)
[1575]140return REQUEST.RESPONSE.redirect(url)
[1106]141
Note: See TracBrowser for help on using the repository browser.