Index: WAeUP_SRP/trunk/Students.py
===================================================================
--- WAeUP_SRP/trunk/Students.py	(revision 1648)
+++ WAeUP_SRP/trunk/Students.py	(revision 1649)
@@ -16,4 +16,5 @@
 from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser
 from Products.WAeUP_SRP.Academics import makeCertificateCode
+from Products.AdvancedQuery import Eq, Between, Le,In
 import logging
 import csv,re,os
@@ -1428,23 +1429,26 @@
         return "Level %s" % self.aq_parent.getId()
 
-##    security.declarePublic("gpa")
-##    def gpa(self):
-##        """calculate the gpa"""
-##        sum = 0
-##        course_count = 0
-##        for sc in self.objectValues():
-##            result = sc.getContent()
-##            if not result.grade:
-##                continue
-##            res = self.portal_catalog({'meta_type': 'Course',
-##                                          'id': sc.aq_parent.id})
-##            if len(res) != 1:
-##                continue
-##            course = res[0].getObject().getContent()
-##            sum += course.credits * ['F','E','D','C','B','A'].index(result.grade)
-##            course_count += 1
-##        if course_count:
-##            return sum/course_count
-##        return 0.0
+    def create_course_results(self,cert_id,current_level):
+        "create all courses in a level"
+        aq_portal = self.portal_catalog.evalAdvancedQuery
+        res = self.portal_catalog(portal_type="Certificate", id = cert_id)
+        l = []
+        import transaction
+        if res:
+            cert = res[0]
+            path = cert.getPath()
+            query = Eq("path","%s/%s" % (path,current_level)) &\
+                    Eq('portal_type','CertificateCourse')
+            courses = aq_portal(query)
+            #from pdb import set_trace;set_trace()
+            self_proxy = self.aq_parent
+            for c in courses:
+                d = self.getCourseInfo(c.getId)
+                cr_id = self_proxy.invokeFactory('StudentCourseResult',c.getId)
+                course_result = getattr(self_proxy,cr_id)
+                self.portal_workflow.doActionFor(course_result,'open')
+                d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
+                course_result.getContent().edit(mapping=d)
+                transaction.commit()
 
 InitializeClass(StudentStudyLevel)
