Index: /WAeUP_SRP/trunk/skins/waeup_student/clearance_edit.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/clearance_edit.py	(revision 1097)
+++ /WAeUP_SRP/trunk/skins/waeup_student/clearance_edit.py	(revision 1098)
@@ -17,4 +17,5 @@
 import logging
 logger = logging.getLogger('Student.Clearance.Edit')
+request = REQUEST
 
 cpsdocument_edit_button = REQUEST.has_key('cpsdocument_edit_button')
@@ -22,4 +23,5 @@
 clear_and_validate_button = REQUEST.has_key('clear_and_validate_button')
 reject_clearance_button = REQUEST.has_key('reject_clearance_button')
+result_edit_button = REQUEST.has_key('result_edit_button')
 
 # Until ajax posts directly to its own script...
@@ -32,19 +34,62 @@
 info = context.getClearanceInfo()
 
-
 #'Sorry, you are not allowed to access this page!'
 if info == None:
-  #return REQUEST.RESPONSE.redirect(context.portal_url())
   return REQUEST.RESPONSE.redirect(context.standard_error_message())
-
-
 student = info['student']
-app = info['app']
-app_doc = info['app_doc']
+#app = info['app']
+#app_doc = info['app_doc']
 clear = info['clear']
 clear_doc = info['clear_doc']
 student_id = info['id']
 member_id = str(context.portal_membership.getAuthenticatedMember())
+result_widgets = ('fst_sit_results',
+                  'scd_sit_results',
+                  'alr_results',
+                  )
+required_scans = ('fst_sit_scan',
+                  'jamb_slip',
+                  'ref_letter',
+                  'acc_let'
+                  )
+form = request.form
+psm = ""
+args = {}
+action = "/external_clearance_edit_form"
+if context.isStudent():
+    action = "/clearance_edit_form"
 
+##if result_edit_button:
+##    dict = {}
+##    for w in result_widgets:
+##        if form.has_key("%s_s" % w):
+##            v = getattr(clear_doc,w)
+##            s = form.get("%s_s" % w)
+##            g = form.get("%s_g" % w)
+##            while 1:
+##                if not s and g:
+##                    break
+##                i = 0
+##                done = False
+##                for sv,gv in v:
+##                    if sv == s:
+##                        done = True
+##                        if not g:
+##                            v.pop(i)
+##                            break
+##                        v[i] = (s,g)
+##                        break
+##                    i += 1
+##                if done:
+##                    break
+##                if s and g:
+##                    v.append((s,g))
+##                break
+##            dict[w] = v
+##            #request.SESSION.set(w,v)
+##    clear_doc.edit(mapping=dict)
+##    args['portal_status_message'] = "Results updated"
+##    url = clear.absolute_url() + action + '?' + urlencode(args)
+##    REQUEST.RESPONSE.redirect(url)
 is_valid, ds = clear_doc.validate(request=REQUEST,
                                 schema_id = 'student_clearance',
@@ -53,12 +98,7 @@
                                 use_session=True)
 
-psm = ""
-args = {}
-action = "/external_clearance_edit_form"
-if context.isStudent():
-    action = "/clearance_edit_form"
 
 if is_valid:
-    if cpsdocument_edit_button:
+    if cpsdocument_edit_button or result_edit_button:
         psm = "Content changed!"
         logger.info('"%s","edited clearance of","%s"' % (member_id,student_id ))
@@ -74,11 +114,24 @@
     elif cpsdocument_edit_and_view_button:
         if acknowledge and info['review_state'] == "clearance_pin_entered":
-            logger.info('"%s","requested clearance"' % (student_id))
-            info['clear_doc'].edit(mapping = {'request_date': current,})
-            wftool.doActionFor(info['clear'],'close')
-            wftool.doActionFor(info['student'],'request_clearance',dest_container=1)
-            psm = "You successfully requested clearance!"
-            if context.isStudent():
-               action = "/clearance_view"
+            missing = False
+            for scan in required_scans:
+                if not hasattr(clear_doc,scan):
+                    missing = True
+                    break
+            if not missing:
+                if not hasattr(clear_doc,"age_dec") and\
+                not hasattr(clear_doc,"birth_certificate"):
+                    missing = True
+            if missing:
+                logger.info('"%s","requested clearance with documents missing"' % (student_id))
+                psm = "You have not uploaded all necessary documents to request clearance"
+            else:
+                logger.info('"%s","requested clearance"' % (student_id))
+                info['clear_doc'].edit(mapping = {'request_date': current,})
+                wftool.doActionFor(info['clear'],'close')
+                wftool.doActionFor(info['student'],'request_clearance',dest_container=1)
+                psm = "You successfully requested clearance!"
+                if context.isStudent():
+                    action = "/clearance_view"
         elif acknowledge and info['review_state'] != "clearance_pin_entered":
             logger.info('"%s","repeatedly requested clearance"' % (student_id))
