Index: WAeUP_SRP/trunk/skins/waeup_student/create_level.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_student/create_level.py	(revision 1497)
+++ WAeUP_SRP/trunk/skins/waeup_student/create_level.py	(revision 1498)
@@ -14,4 +14,5 @@
 from Products.AdvancedQuery import Eq, Between, Le,In
 aq_portal = context.portal_catalog.evalAdvancedQuery
+aq_courses = context.courses_catalog.evalAdvancedQuery
 
 current = DateTime.DateTime()
@@ -21,5 +22,4 @@
 redirect = response.redirect
 logger = logging.getLogger('Student.create_level')
-students = context.portal_directories.students
 mtool = context.portal_membership
 member = mtool.getAuthenticatedMember()
@@ -49,8 +49,30 @@
 results = context.results_import(matric_no = student.matric_no)
 if results:
-    carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
-    #carry_overs = [brain for brain in results if int(brain.Score) < 40 ]
+    #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
     l = []
+    carry_overs = results
     for co in carry_overs:
+        carry_over = False
+        query = Eq('code',co.CosCode)
+        c_res = aq_courses(query)
+        if not c_res:
+            logger.info('"%s","%s course not found in courses catalog"' % (student.id,co.CosCode))
+            continue
+        course_cat_entry = c_res[0]
+        if not course_cat_entry.passmark:
+            carry_over = co.GRADE in ('D','E','F')
+        else:
+            try:
+                score = int(co.Score)
+            except:
+                logger.info('"%s"," course %s invalid score %s"' % (student.id,
+                                                                    co.CosCode,
+                                                                    co.Score))
+                continue
+            if int(c_res[0].passmark) <= score:  
+                continue
+            carry_over = True
+        if not carry_over:
+            continue
         d = context.getCourseInfo(co.CosCode)
         d['grade'] = co.GRADE
@@ -77,3 +99,4 @@
         course_result.getContent().edit(mapping=d)
 session.set('in_progress','finished')
+return
 return response.redirect("%s" % level.absolute_url())
Index: WAeUP_SRP/trunk/skins/waeup_utilities/reindexCoursesCatalog.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_utilities/reindexCoursesCatalog.py	(revision 1498)
+++ WAeUP_SRP/trunk/skins/waeup_utilities/reindexCoursesCatalog.py	(revision 1498)
@@ -0,0 +1,78 @@
+## Script (Python) "search_pins"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=REQUEST
+##title=
+##
+# $Id$
+"""
+list Students for ClearanceOfficers
+"""
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+
+request = context.REQUEST
+session = request.SESSION
+response = request.RESPONSE
+setheader = request.RESPONSE.setHeader
+import logging
+logger = logging.getLogger('fixLevelForNewStudents')
+
+def rwrite(s):
+    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
+    response.write(s)
+
+mtool = context.portal_membership
+member = mtool.getAuthenticatedMember()
+#students_cat = context.students_catalog
+courses_cat = context.courses_catalog
+from Products.AdvancedQuery import Eq, Between, Le,In
+#aq_students = students_cat.evalAdvancedQuery
+aq_portal = context.portal_catalog.evalAdvancedQuery
+students = context.portal_url.getPortalObject().campus.students
+
+count = 0
+##query = Eq('portal_type','Student') & In('review_state',('admitted',
+##                                                         'clearance_requested',
+##                                                         'cleared_and_validated',
+##                                                         'objection_raised',
+##                                                         )
+##res = aq_portal(query)
+query = Eq('portal_type','Course')
+courses = aq_portal(query)
+#set_trace()
+count = 0
+count_full = 0
+commit_count = 0
+logger.info("reindexing of courses_catalog started for %s courses" % len(courses))
+for course_brain in courses:
+    course_doc = course_brain.getObject().getContent()
+    d = {}
+    d['code'] = getattr(course_doc,'code')
+    d['credits'] = getattr(course_doc,'credits')
+    d['level'] = getattr(course_doc,'level')
+    d['passmark'] = getattr(course_doc,'passmark')
+    d['semester'] = getattr(course_doc,'semester')
+    d['title'] = getattr(course_doc,'title')
+    pl = course_brain.getPath().split('/')
+    d['faculty'] = pl[-4]
+    d['department'] = pl[-3]
+    try:
+        courses_cat.modifyRecord(**d)
+    except KeyError:
+        courses_cat.addRecord(**d)
+    count += 1
+    commit_count += 1
+    if commit_count > 1000:
+        context.waeup_tool.doCommit()
+        logger.info("committing %s transactions total %s" % (commit_count,count))
+        rwrite("%s: committed %s <br />" % (count,commit_count))
+        commit_count = 0
+rwrite("finished")
+logger.info("finished  reindexing %s courses" % count)
