Index: WAeUP_SRP/base/WAeUPTables.py
===================================================================
--- WAeUP_SRP/base/WAeUPTables.py	(revision 2765)
+++ WAeUP_SRP/base/WAeUPTables.py	(revision 2766)
@@ -536,5 +536,5 @@
             raise ValueError("More than one record with uid %s" % uid)
         if len(records) == 0:
-            return -1
+            return -1,None
         record = records[0]
         if record.student == "":
@@ -546,12 +546,12 @@
             try:
                 self.catalog_object(dict2ob(record_data), uid)
-                return 1
+                return 1,record
             except ConflictError:
-                return 2
+                return 2,record
         if record.student.upper() != student_id.upper():
-            return 0
+            return 0,record
         if record.student.upper() == student_id.upper():
-            return 2
-        return -3
+            return 2,record
+        return -3,record
 InitializeClass(PinTable)
 ###)
Index: WAeUP_SRP/base/WAeUPTool.py
===================================================================
--- WAeUP_SRP/base/WAeUPTool.py	(revision 2765)
+++ WAeUP_SRP/base/WAeUPTool.py	(revision 2766)
@@ -1445,34 +1445,41 @@
         if course_id not in self._v_courses.keys():
             return '', "No course with ID: %s" % course_id
-        id_key = ''
-        for id_key in ('student_id','matric_no'):
-            id_field = mapping.get(id_key,None)
-            if id_field is not None:
-                student_id = id_field
-                break
-        query = Eq(id_key,id_field)
-        res = self.students_catalog.evalAdvancedQuery(query)
-        if not res:
+        # id_key = ''
+        # for id_key in ('student_id','matric_no'):
+        #     id_field = mapping.get(id_key,None)
+        #     if id_field is not None:
+        #         student_id = id_field
+        #         break
+        # query = Eq(id_key,id_field)
+        # res = self.students_catalog.evalAdvancedQuery(query)
+        student_rec = self.students_catalog.getRecordByKey(mapping['student_id'])
+        if student_rec is None:
             return '', "no student with %(id_key)s %(id_field)s" % vars()
-        if id_field != "student_id":
-            mapping['student_id'] = res[0].id
+        # if id_field != "student_id":
+        #     mapping['student_id'] = res[0].id
+        student_id = student_rec.id
+        level_id = mapping['level_id']
+        code = mapping['code']
         if mapping['student_id'] not in self._v_level_created:
             try:
                 context = getattr(getattr(students_folder,
-                                          "%(student_id)s" % mapping),
+                                          "%(student_id)s" % vars()),
                                   'study_course')
             except:
-                return '', "could not create level %(level_id)s for %(student_id)s" % mapping
-            if mapping['level_id'] not in context.objectIds():
-                context.invokeFactory('StudentStudyLevel',"%(level_id)s" % mapping)
-                level = getattr(context,"%(level_id)s" % mapping)
+                return '', "could not create level %(level_id)s for %(student_id)s" % vars()
+            if level_id not in context.objectIds():
+                context.invokeFactory('StudentStudyLevel',"%(level_id)s" % vars())
+                level = getattr(context,"%(level_id)s" % vars())
                 self.portal_workflow.doActionFor(level,'open')
-
                 # the session string must not be copied into the level object
-                #level.getContent().edit(mapping={'session': "%(session_id)s" % mapping})
-
-                #self.portal_workflow.doActionFor(level,'close_for_edit')
-            self._v_level_created += mapping['student_id'],
-        mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % mapping
+                if student_rec.current_verdict:
+                    level.getContent().edit(mapping={'verdict': "%s" % 
+                                                     student_rec.current_verdict,
+                                                     'session': "%s" % 
+                                                     student_rec.current_session,
+                                                    })
+                    self.portal_workflow.doActionFor(level,'close')
+            self._v_level_created += student_id,
+        mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars()
         for k in ('semester','credits',):
             mapping[k] = getattr(self._v_courses[course_id],k)
@@ -1495,17 +1502,24 @@
         # if course_id not in self._v_courses.keys():
         #     return '', "No course with ID: %s" % did
-        id_key = ''
-        for id_key in ('student_id','matric_no'):
-            id_field = mapping.get(id_key,None)
-            if id_field is not None:
-                student_id = id_field
-                break
-        query = Eq(id_key,id_field)
-        res = self.students_catalog.evalAdvancedQuery(query)
-        if not res:
-            return '', "No student with %(id_field)s: %(id_key)s" % vars()
-        if id_field != "student_id":
-            mapping['student_id'] = res[0].id
-        mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % mapping
+        # id_key = ''
+        # for id_key in ('student_id','matric_no'):
+        #     id_field = mapping.get(id_key,None)
+        #     if id_field is not None:
+        #         student_id = id_field
+        #         break
+        # query = Eq(id_key,id_field)
+        # res = self.students_catalog.evalAdvancedQuery(query)
+        # if not res:
+        #     return '', "No student with %(id_field)s: %(id_key)s" % vars()
+        # if id_field != "student_id":
+        #     mapping['student_id'] = res[0].id
+        students_folder = self.portal_url.getPortalObject().campus.students
+        student_rec = self.students_catalog.getRecordByKey(mapping['student_id'])
+        if student_rec is None:
+            return '', "no student with %(id_key)s %(id_field)s" % vars()
+        student_id = student_rec.id
+        level_id = mapping['level_id']
+        code = mapping['code']
+        mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars()
         # for k in ('semester',):
         #     mapping[k] = getattr(self._v_courses[course_id],k)
@@ -1514,4 +1528,21 @@
         except KeyError:
             return '', "No course result to edit: %s" % key
+        if student_rec.current_verdict:
+            #makes only sense if the course_results are imported for the current session
+            try:
+                level = getattr(getattr(getattr(students_folder,
+                                                "%(student_id)s" % vars()),
+                                        'study_course'),
+                                "%(level_id)s" % vars())
+            except:
+                return '', "could not find level %(level_id)s for %(student_id)s" % vars()
+            if self.portal_workflow.getInfoFor(level,'review_state',None) == "closed":
+                self.portal_workflow.doActionFor(level,'open')
+            level.getContent().edit(mapping={'verdict': "%s" % 
+                                                student_rec.current_verdict,
+                                                'session': "%s" % 
+                                                student_rec.current_session,
+                                            })
+            self.portal_workflow.doActionFor(level,'close')
         return key,''
     ###)
Index: WAeUP_SRP/base/Widgets.py
===================================================================
--- WAeUP_SRP/base/Widgets.py	(revision 2765)
+++ WAeUP_SRP/base/Widgets.py	(revision 2766)
@@ -24,4 +24,5 @@
 #from Products.ExtFile.ExtFile import ExtFile
 import logging,os,re
+import random
 import operator
 p_home = Globals.package_home(globals())
@@ -31,5 +32,5 @@
 
 
-class WAeUPPasswordWidget(CPSPasswordWidget):
+class WAeUPPasswordWidget(CPSPasswordWidget): ###(
     """WAeUP Password Widget"""
     meta_type = 'WAeUP Password Widget'
@@ -117,5 +118,5 @@
 
 widgetRegistry.register(WAeUPPasswordWidget)
-
+###)
 
 class CPSSelectWidgetForRecord(CPSSelectWidget): ###(
@@ -1320,5 +1321,5 @@
 
         while do:
-            ok = pins.searchAndSetRecord(pin,ref,prefix)
+            ok,record = pins.searchAndSetRecord(pin,ref,prefix)
             if ok < -2 or ok > 2:
                 err = 'Unknown error, please report!'
@@ -1473,5 +1474,4 @@
     def validate(self, datastructure, **kw): ###(
         """Validate datastructure and update datamodel."""
-        #import pdb;pdb.set_trace()
         s_logger = logging.getLogger('Widgets.ScratchcardPinWidget.validate')
         widget_id = self.getWidgetId()
@@ -1519,5 +1519,5 @@
                 s_logger.info('%s/%s entered wrong data together with PIN %s' % (member_id,ref,pin_str))
         while do:
-            ok = pins.searchAndSetRecord(pin,ref,prefix)
+            ok,pin_record = pins.searchAndSetRecord(pin,ref,prefix)
             if ok < -2 or ok > 2:
                 err = 'Unknown error, please report!'
@@ -1556,4 +1556,6 @@
                         d['reg_no'] = applicant.reg_no
                         d['pin'] = pin_str
+                        d['serial'] = "%c%05d" % (pin_record.prefix_batch[-1],
+                                                  pin_record.serial)
                         #d['screening_type'] = screening_type
                         #d['status'] = 'entered'
Index: WAeUP_SRP/base/skins/waeup_pins/pins_view.pt
===================================================================
--- WAeUP_SRP/base/skins/waeup_pins/pins_view.pt	(revision 2765)
+++ WAeUP_SRP/base/skins/waeup_pins/pins_view.pt	(revision 2766)
@@ -62,5 +62,5 @@
                 >
           <option value="--">Goto Batch ...</option>
-          <option tal:repeat="batch context/objectIds"
+          <option tal:repeat="batch info/batches"
                   tal:attributes="value batch"
                   tal:content="batch">
Index: WAeUP_SRP/base/skins/waeup_pins/search_pins.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_pins/search_pins.py	(revision 2765)
+++ WAeUP_SRP/base/skins/waeup_pins/search_pins.py	(revision 2766)
@@ -109,4 +109,7 @@
     view = context.batch_view
 elif context.portal_type == "ScratchCardBatchesFolder":
+    batches = context.objectIds()
+    batches.sort()
+    info['batches'] = batches
     view = context.pins_view
 if psm == '':
Index: WAeUP_SRP/base/skins/waeup_student/create_level.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_student/create_level.py	(revision 2765)
+++ WAeUP_SRP/base/skins/waeup_student/create_level.py	(revision 2766)
@@ -39,5 +39,5 @@
 lt = context.portal_layouts
 wt = context.waeup_tool
-student = context.students_catalog(id=student_id)[0]
+student = context.students_catalog.getRecordByKey(student_id)
 cert_id = student.course
 current_level = student.level
@@ -51,5 +51,6 @@
 
 if context.hasObject(current_level):
-    level = getattr(context,"%s" % current_level)
+    #level = getattr(context,"%s" % current_level)
+    return response.redirect("%s/%s" % (context.absolute_url(),current_level))
 else:
     context.invokeFactory('StudentStudyLevel',"%s" % current_level)
@@ -65,5 +66,4 @@
     results = context.results_import(matric_no = student.matric_no)
 l = []
-
 
 # fetch carry_over courses from results_import
@@ -110,5 +110,37 @@
         records.append(d)
 # fetch carry_over courses from the course_results catalog
-# else
+else:
+    res = context.aq_results(Eq('student_id',student_id),
+                             sortSpecs=('level_id',))
+    last_level_id = res[-1].level_id
+    for result in res:
+        course_id = result.code
+        if course_id in l or result.level_id != last_level_id: 
+            continue
+        query = Eq('code',course_id)
+        c_res = aq_courses(query)
+        if not c_res:
+            #logger.info('%s", course %s not found in courses_catalog' % (student.id,result.CosCode))
+            continue
+        course_cat_entry = c_res[0]
+        passmark = getattr(course_cat_entry,'passmark',None)
+        try:
+            score = int(result.score)
+        except:
+            # logger.info('%s, course %s has invalid score %s"' % (student.id,
+            #                                                     course_id,
+            #                                                     result.Score))
+            continue
+        if int(c_res[0].passmark) <= score:
+            continue
+        l += course_id,
+        d = context.getCourseInfo(course_id)
+        d['course_id'] = course_id
+        d['carry_over'] = True
+        d['code'] = course_id
+        d['student_id'] = student_id
+        d['level_id'] = level_id
+        d['session_id'] = session_id
+        records.append(d)
 
 # fetch session courses from the certificate
Index: WAeUP_SRP/uniben/profiles/default/applicants_catalog.xml
===================================================================
--- WAeUP_SRP/uniben/profiles/default/applicants_catalog.xml	(revision 2765)
+++ WAeUP_SRP/uniben/profiles/default/applicants_catalog.xml	(revision 2766)
@@ -17,4 +17,5 @@
  <column value="phone"/>
  <column value="pin"/>
+ <column value="serial"/>
  <column value="eng_score"/>
  <column value="subj1"/>
@@ -59,4 +60,7 @@
   <indexed_attr value="reg_no"/>
  </index>
+ <index name="serial" meta_type="FieldIndex">
+  <indexed_attr value="serial"/>
+ </index>
  <index name="status" meta_type="FieldIndex">
   <indexed_attr value="status"/>
Index: WAeUP_SRP/uniben/profiles/default/layouts/application_cest.xml
===================================================================
--- WAeUP_SRP/uniben/profiles/default/layouts/application_cest.xml	(revision 2765)
+++ WAeUP_SRP/uniben/profiles/default/layouts/application_cest.xml	(revision 2766)
@@ -815,4 +815,7 @@
     </row>
     <row>
+      <cell name="serial" ncols="2"/>
+    </row>
+    <row>
       <cell name="firstname" ncols="2"/>
     </row>
