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

Last change on this file since 1098 was 1098, checked in by joachim, 18 years ago

check for missing files

  • Property svn:keywords set to Id
File size: 6.3 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 1098 2006-12-20 01:40:01Z joachim $
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('Student.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_letter',
53                  'acc_let'
54                  )
55form = request.form
56psm = ""
57args = {}
58action = "/external_clearance_edit_form"
59if context.isStudent():
60    action = "/clearance_edit_form"
61
62##if result_edit_button:
63##    dict = {}
64##    for w in result_widgets:
65##        if form.has_key("%s_s" % w):
66##            v = getattr(clear_doc,w)
67##            s = form.get("%s_s" % w)
68##            g = form.get("%s_g" % w)
69##            while 1:
70##                if not s and g:
71##                    break
72##                i = 0
73##                done = False
74##                for sv,gv in v:
75##                    if sv == s:
76##                        done = True
77##                        if not g:
78##                            v.pop(i)
79##                            break
80##                        v[i] = (s,g)
81##                        break
82##                    i += 1
83##                if done:
84##                    break
85##                if s and g:
86##                    v.append((s,g))
87##                break
88##            dict[w] = v
89##            #request.SESSION.set(w,v)
90##    clear_doc.edit(mapping=dict)
91##    args['portal_status_message'] = "Results updated"
92##    url = clear.absolute_url() + action + '?' + urlencode(args)
93##    REQUEST.RESPONSE.redirect(url)
94is_valid, ds = clear_doc.validate(request=REQUEST,
95                                schema_id = 'student_clearance',
96                                layout_id = 'student_clearance',
97                                proxy=clear,
98                                use_session=True)
99
100
101if is_valid:
102    if cpsdocument_edit_button or result_edit_button:
103        psm = "Content changed!"
104        logger.info('"%s","edited clearance of","%s"' % (member_id,student_id ))
105        if clear_doc.clr_ac_pin == "":
106            res = context.portal_pins(student=member_id)
107            if res:
108                p = res[0].pin
109                if len(p) > 10:
110                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
111                else:
112                    pin = p
113                clear_doc.edit(mapping={'clr_ac_pin': pin})
114    elif cpsdocument_edit_and_view_button:
115        if acknowledge and info['review_state'] == "clearance_pin_entered":
116            missing = False
117            for scan in required_scans:
118                if not hasattr(clear_doc,scan):
119                    missing = True
120                    break
121            if not missing:
122                if not hasattr(clear_doc,"age_dec") and\
123                not hasattr(clear_doc,"birth_certificate"):
124                    missing = True
125            if missing:
126                logger.info('"%s","requested clearance with documents missing"' % (student_id))
127                psm = "You have not uploaded all necessary documents to request clearance"
128            else:
129                logger.info('"%s","requested clearance"' % (student_id))
130                info['clear_doc'].edit(mapping = {'request_date': current,})
131                wftool.doActionFor(info['clear'],'close')
132                wftool.doActionFor(info['student'],'request_clearance',dest_container=1)
133                psm = "You successfully requested clearance!"
134                if context.isStudent():
135                    action = "/clearance_view"
136        elif acknowledge and info['review_state'] != "clearance_pin_entered":
137            logger.info('"%s","repeatedly requested clearance"' % (student_id))
138            psm = "You have already requested clearance!"
139        else:
140            psm = "You must tick the acknowledgement check box before submission!"
141    elif clear_and_validate_button and info['review_state'] == "clearance_requested":
142        logger.info('"%s","cleared","%s"' % (member_id,student_id ))
143        #from Products.zdb import set_trace
144        #set_trace()
145        info['clear_doc'].edit(mapping = {'cleared_date': current,})
146        wftool.doActionFor(info['student'],'clear_and_validate')
147        psm = "Clearance and eligibility record is validated and and student is cleared!"
148    elif clear_and_validate_button and info['review_state'] == "cleared_and_validated":
149        psm = "This student is already cleared!"
150    elif reject_clearance_button:
151        logger.info('"%s","rejected clearance for","%s"' % (member_id,student_id ))
152        wftool.doActionFor(info['clear'],'open')
153        wftool.doActionFor(info['student'],'reject_clearance')
154        action = "/contact_student_form"
155        psm = "Student's clearance request has been rejected! Please fill and submit the form below!"
156else:
157    psm = "Please correct your errors!"
158    args = getFormUidUrlArg(REQUEST)
159
160args['portal_status_message'] = psm
161url = clear.absolute_url() + action + '?' + urlencode(args)
162REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.