Index: /WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py	(revision 2101)
+++ /WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py	(revision 2102)
@@ -29,4 +29,5 @@
 apply_pume = "apply" in request.keys()
 edit = "edit" in request.keys()
+submitted = False
 mode = request.get('mode','')
 if not mode:
@@ -40,8 +41,7 @@
 reg_no = request.get('widget__reg_no','').upper()
 if not reg_no:
-    reg_no = request.get('reg_no','').upper()
-    
+    reg_no = request.form.get('reg_no','').upper()
+pin = request.form.get('pin','')
 object = {}
-#set_trace()
 if reg_no:
     brains = context.applicants_catalog(reg_no = reg_no)
@@ -49,4 +49,9 @@
         for field in context.applicants_catalog.schema():
             object[field] = getattr(brains[0],field,None)
+        if object['status'] == "submitted":
+            submitted = True
+        #set_trace()
+        if not create and pin != object['pin']:
+            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
 
 res,psm,ds = lt.renderLayout(layout_id= 'application',
@@ -59,4 +64,5 @@
                             )
 
+set_trace()
 if psm == 'invalid':
     return context.apply_pume_form(rendered = res,
@@ -74,28 +80,46 @@
 elif psm == 'valid':
     pass
-if create or edit or apply_pume:
-    data = {}
-    for field in context.applicants_catalog.schema():
-        if ds.has_key(field) and request.has_key("widget__%s" % field):
-            data[field] = ds.get(field)
-    data['reg_no'] = reg_no
-    if apply_pume:
-        data['registration_date'] = current
-        data['status'] = "submitted"
-    context.applicants_catalog.modifyRecord(**data)
-    if apply_pume:
-        if not request.has_key('confirm'):
-            return context.apply_pume_form(rendered = res,
-                                        psm = "Please confirm Passport Photograph",
-                                        #psm = "%s, %s" % (psm,ds),
-                                        mode = mode,
-                                        ds = ds,
-                                        )
-                    
-        return request.RESPONSE.redirect("%s/apply_pume?mode=view&reg_no=%s" %
-                                     (context.absolute_url(),ds.get('reg_no')))
-    elif edit or create:
-        return request.RESPONSE.redirect("%s/apply_pume?mode=edit&reg_no=%s" %
-                                     (context.absolute_url(),ds.get('reg_no')))
+data = {}
+for field in context.applicants_catalog.schema():
+    if ds.has_key(field) and request.has_key("widget__%s" % field):
+        data[field] = ds.get(field)
+data['reg_no'] = reg_no
+if apply_pume:
+    data['registration_date'] = current
+    data['status'] = "submitted"
+context.applicants_catalog.modifyRecord(**data)
+if apply_pume:
+    if not request.has_key('confirm'):
+        mode = "edit"
+        psm = "Please confirm Passport Photograph"
+    else:
+        mode = "view"
+        psm = "You successfully applied for PUME"
+elif create:
+    if submitted:
+        mode = "view"
+    else:
+        mode = "edit"
+    psm = ""
+    #set_trace()
+    object['pin'] = str(ds.get('pin'))
+    res,psm,dummy = lt.renderLayout(layout_id= 'application',
+                                schema_id= 'application',
+                                layout_mode = mode,
+                                context=context,
+                                mapping={},
+                                ob=object,
+                                commit = False,
+                                )
+elif edit:
+    mode = "edit"
+    psm = "Content changed"
+
+return context.apply_pume_form(rendered = res,
+                            psm = psm,
+                            #psm = "%s, %s" % (psm,ds),
+                            mode = mode,
+                            ds = ds,
+                            )
 
 
