Index: WAeUP_SRP/base/skins/cps_custom/logged_in.py
===================================================================
--- WAeUP_SRP/base/skins/cps_custom/logged_in.py	(revision 2342)
+++ WAeUP_SRP/base/skins/cps_custom/logged_in.py	(revision 2407)
@@ -45,4 +45,10 @@
         student_app = getattr(student,'application',None)
         student_per = getattr(student,'personal',None)
+        
+        #########################################################
+        
+        # perform makeStudentData for returning students who login for the first time
+        # the returning key comes from set_access_data
+              
         if request.has_key('returning') and  student_app is None:
             email=request.get("email")
@@ -60,4 +66,9 @@
             context.waeup_tool.makeStudentData(str(member))
         student_app = getattr(student,'application',None)
+        
+        #########################################################
+        
+        # add missing payments folders
+        
         if 'payments' not in student.objectIds():
             student.invokeFactory('PaymentsFolder','payments')
@@ -67,5 +78,8 @@
             d['Title'] = 'Online Payments'
             payments.getContent().edit(mapping=d)
-        student_pume = getattr(student,'pume',None)
+            
+        #########################################################            
+            
+        #student_pume = getattr(student,'pume',None)
         s_review_state = context.getStudentReviewState(student.id)
         a_review_state = wftool.getInfoFor(student_app,'review_state',None)
@@ -74,4 +88,8 @@
         logger.info('%s logged in, review_state %s' % (member,s_review_state))
         app_doc = student_app.getContent()
+
+        #########################################################
+        
+        # save email and phone of returning students after all objects have been created
 
         if request.has_key('returning'):
@@ -88,6 +106,9 @@
             per_doc.edit(mapping = {'email' : email, 'phone' : phone})
             wftool.doActionFor(student_app,'close')
-
-        #from Products.zdb import set_trace;set_trace()
+            
+        #########################################################     
+        
+        # look for passport pictures of returning students
+
         if s_review_state == 'returning' and 'passport' not in app_doc.objectIds():
             folder = 'pictures_returning'
@@ -96,4 +117,10 @@
             msg = context.waeup_tool.loadStudentFoto(student,filename,folder)
             logger.info('%s (%s), %s' % (member,s_review_state,msg))
+
+
+        #########################################################
+        
+        # look for passport pictures of new students
+
         if s_review_state in ('admitted', 'clearance_pin_entered', 'clearance_requested')  and 'passport' not in app_doc.objectIds():
             folder = 'pictures_admitted_latest'
@@ -101,11 +128,21 @@
             msg = context.waeup_tool.loadStudentFoto(student,filename,folder)
             logger.info('%s (%s), %s' % (member,s_review_state,msg))
+
+
+        #########################################################
+        
+        # perform necessary updates for new students
+
+        # 1. add pin and application date to app_doc
+        
         if s_review_state in ("student_created","admitted") and\
                              a_review_state == 'created' :
             wftool.doActionFor(student_app,'open')
-            if student_pume is not None:
-              wftool.doActionFor(student_pume,'close')
+            #if student_pume is not None:
+            #  wftool.doActionFor(student_pume,'close')
             da = {}
             pin = request.get('pin')
+            
+            # if the student comes directly, add missing pin (fix)
             if not pin:
                 jamb_reg_no = app_doc.jamb_reg_no
@@ -123,4 +160,7 @@
             da['app_ac_date'] = current
             app_doc.edit(mapping = da)
+            
+        # 2. same as 1 but without opening app_doc    
+            
         elif s_review_state in ("admitted") and a_review_state == 'opened' and\
                                             not app_doc.app_ac_pin:
@@ -139,10 +179,21 @@
                 da['app_ac_pin'] = pin
                 app_doc.edit(mapping = da)
+                
+        # 2. open personal object. This should be done in clearance_edit.       
+                
         elif s_review_state in ("cleared_and_validated",) and\
                              p_review_state == 'created' :
             wftool.doActionFor(student_per,'open')
+            
+        #########################################################
+            
         res = context.students_catalog(id = str(member))
         matric_no = res[0].matric_no
         verdict = res[0].verdict
+
+        #########################################################
+        
+        # fetch current verdict via getVerdict
+
         if s_review_state in ('returning','school_fee_paid') and not verdict:
             results = context.results_import(matric_no = matric_no)
@@ -157,5 +208,13 @@
                 study_course_doc.edit(mapping = dsc)
                 wftool.doActionFor(study_course,'close_for_edit')
+                
+        #########################################################
+                
         has_results = context.results_import(matric_no = matric_no)
+
+        #########################################################
+        
+        # determine appropriate redirect url
+
         if s_review_state == "application_pin_entered":
             redirect_url = "%s/application_edit_form" % student.absolute_url()
@@ -172,4 +231,6 @@
         else:
             redirect_url = "%s/student_index" % student.absolute_url()
+
+
     else:
         logger.info('%s logged in' % (member))
