Index: WAeUP_SRP/base/skins/waeup_student/apply_admission.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_student/apply_admission.py	(revision 3410)
+++ WAeUP_SRP/base/skins/waeup_student/apply_admission.py	(revision 3411)
@@ -104,4 +104,6 @@
     if apply_admission or edit or manage:
         mode = "edit"
+    elif slip:
+        mode = "view_slip"
     else:
         mode = "create"
@@ -114,91 +116,85 @@
 
 lt = context.portal_layouts
-
+object = {}
 pin = request.form.get('pin','')
 # reg_no = request.get('widget__reg_no','').upper()
 # if not reg_no:
 #     reg_no = request.form.get('reg_no','').upper()
-reg_no = request.form.get('reg_no','').upper()
-# if not reg_no:
-#     reg_no = request.get('widget__pin_n','').upper()
-object = {}
-if reg_no:
-    brains = context.applicants_catalog(reg_no = reg_no)
-    if len(brains) == 1:
-        for field in context.applicants_catalog.schema():
-            object[field] = getattr(brains[0],field,None)
-        if not object['passport']:
-                object['passport'] = ''
-        if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']):
-            submitted = True
-
-        if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
-            logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
-            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
-
-        # For the next application session it should be reverted to
-        # (see comment 09/06/07 16:40:52 in ticket #328):
-
-        #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
-            #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
-            #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
+
+
+screening_type = 'pume'
+if traverse_subpath and traverse_subpath[0] in screening_types:
+    screening_type = traverse_subpath[0]
+layout = "application_%s" % screening_type
 info = {}
-info['status'] = object.get('status','')
-if traverse_subpath and traverse_subpath[0] in screening_types:
-    screening_type = info['screening_type'] = traverse_subpath[0]
-elif manage:
-    if object['screening_type']:
-        st = object['screening_type']
-    else:
-        st = 'pume'
-    screening_type = info['screening_type'] = st
-
-for co_name,co_dict in configuration:
-    info[co_name] = co_dict[screening_type]
-layout = "application_%s" % screening_type
 without_reg_no = screening_type in ('prence','cest','sandwich')
 info['expired'] = current.greaterThan(deaddates[screening_type])
 info['expiration_date'] = deaddates[screening_type]
-
-
-if slip:
-    mode = "view_slip"
-    logger.info('%s/%s views application slip' % (member,reg_no))
-
-res,psm,ds = lt.renderLayout(layout_id= layout,
-                             schema_id= 'import_application',
-                             layout_mode = mode,
-                             context=context,
-                             mapping=validate and REQUEST,
-                             ob=object,
-                             commit = False,
-                            )
-if slip:
-    return context.apply_admission_slip(rendered = res,
-                                        psm = "",
-                                        mode = mode,
-                                        ds = ds,
-                                        info = info,
-                                       )
-if psm == 'invalid':
-    return context.apply_admission_form(rendered = res,
-                                        psm = "Please correct your input!",
-                                        mode = mode,
-                                        ds = ds,
-                                        info = info,
-                                       )
-info['reg_no'] = ds.get('reg_no')
-info['pin'] = ds.get('pin')
-if psm == '' and not manage:
-    return context.apply_admission_form(rendered = res,
-                                        psm = psm,
-                                        ds = ds,
-                                        mode = mode,
-                                        info = info,
-                                       )
-# elif psm == 'valid' or (psm == '' and manage):
-#     pass
-if without_reg_no:
-    reg_no = ds.get('reg_no')
+info['status'] = object.get('status','')
+#set_trace()
+# the reg_no is a hidden field in the form
+reg_no = request.form.get('reg_no','').upper()
+if not reg_no:
+    # validate form if no reg_no specified
+    res,psm,ds = lt.renderLayout(layout_id= layout,
+                                schema_id= 'import_application',
+                                layout_mode = mode,
+                                context=context,
+                                mapping=validate and REQUEST,
+                                ob={},
+                                commit = False,
+                                )
+    if psm == 'invalid':
+        return context.apply_admission_form(rendered = res,
+                                            psm = "Please correct your input!",
+                                            mode = mode,
+                                            ds = ds,
+                                            info = info,
+                                        )
+    elif psm == '':
+        return context.apply_admission_form(rendered = res,
+                                            psm = psm,
+                                            ds = ds,
+                                            mode = mode,
+                                            info = info,
+                                           )
+    if without_reg_no:
+        reg_no = ds.get('pin_n','').upper()
+    else:
+        reg_no = ds.get('reg_no')
+info['reg_no'] = reg_no
+brains = context.applicants_catalog(reg_no = reg_no)
+if len(brains) == 1:
+    for field in context.applicants_catalog.schema():
+        object[field] = getattr(brains[0],field,None)
+    screening_type = info['screening_type'] = object['screening_type']
+    for co_name,co_dict in configuration:
+        info[co_name] = co_dict[screening_type]
+    if not object['passport']:
+            object['passport'] = ''
+    if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']):
+        submitted = True
+
+    if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
+        logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
+        return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
+
+    #rerender with current object = application-record
+    res,psm,ds = lt.renderLayout(layout_id= layout,
+                                schema_id= 'import_application',
+                                layout_mode = mode,
+                                context=context,
+                                mapping=validate and REQUEST,
+                                ob=object,
+                                commit = False,
+                                )
+    # For the next application session it should be reverted to
+    # (see comment 09/06/07 16:40:52 in ticket #328):
+
+    #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
+        #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
+        #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
+info['status'] = object.get('status','')
+
 data = {}
 dm = ds.getDataModel()
@@ -207,17 +203,34 @@
         data[field] = dm.get(field)
 data['reg_no'] = reg_no
-if apply_admission:
+if manage:
+    if submitted:
+        mode = "view"
+        psm = "You are now assuming the applicant's role!"
+        logger.info('%s/%s entered application record' % (member,reg_no))
+        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
+        #                         schema_id= 'import_application',
+        #                         layout_mode = mode,
+        #                         context=context,
+        #                         mapping={},
+        #                         ob=object,
+        #                         commit = False,
+        #                         )
+    else:
+        mode = "edit"
+        psm = "You are now assuming the applicant's role!"
+        logger.info('%s/%s entered application record' % (member,reg_no))
+elif apply_admission:
     if submitted:
         mode = "view"
         psm = "The form has already been submitted and you are not allowed to resubmit the data!"
         logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
-        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
-                                schema_id= 'import_application',
-                                layout_mode = mode,
-                                context=context,
-                                mapping={},
-                                ob=object,
-                                commit = False,
-                                )
+        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
+        #                         schema_id= 'import_application',
+        #                         layout_mode = mode,
+        #                         context=context,
+        #                         mapping={},
+        #                         ob=object,
+        #                         commit = False,
+        #                         )
     elif not request.has_key('confirm'):
         mode = "edit"
@@ -236,5 +249,5 @@
         object['status'] = data['status']
         context.applicants_catalog.modifyRecord(**data)
-
+        # rerendering neccessary since object changed
         res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
                                 schema_id= 'import_application',
@@ -256,4 +269,5 @@
         object['reg_no'] = reg_no
     object['pin'] = str(ds.get('pin'))
+    # rerendering neccessary since object changed
     res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
                                 schema_id= 'import_application',
@@ -265,17 +279,16 @@
                                 )
 elif edit:
-    #set_trace()
     if submitted:
         mode = "view"
         psm = "The form has already been submitted and you are not allowed to modify the data!"
         logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
-        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
-                                schema_id= 'import_application',
-                                layout_mode = mode,
-                                context=context,
-                                mapping={},
-                                ob=object,
-                                commit = False,
-                                )
+        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
+        #                         schema_id= 'import_application',
+        #                         layout_mode = mode,
+        #                         context=context,
+        #                         mapping={},
+        #                         ob=object,
+        #                         commit = False,
+        #                         )
     else:
         mode = "edit"
@@ -285,23 +298,4 @@
         context.applicants_catalog.modifyRecord(**data)
         logger.info('%s/%s modified application record' % (member,reg_no))
-
-elif manage:
-    if submitted:
-        mode = "view"
-        psm = "You are now assuming the applicant's role!"
-        logger.info('%s/%s entered application record' % (member,reg_no))
-        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
-                                schema_id= 'import_application',
-                                layout_mode = mode,
-                                context=context,
-                                mapping={},
-                                ob=object,
-                                commit = False,
-                                )
-    else:
-        mode = "edit"
-        psm = "You are now assuming the applicant's role!"
-        logger.info('%s/%s entered application record' % (member,reg_no))
-
 
 try:
