Index: /WAeUP_SRP/trunk/Students.py
===================================================================
--- /WAeUP_SRP/trunk/Students.py	(revision 4301)
+++ /WAeUP_SRP/trunk/Students.py	(revision 4302)
@@ -599,17 +599,17 @@
     ###)
 
-    def generateStudentId(self,letter,students = None): ###(
-        import random
-        r = random
-        if students is None:
-            students = self.portal_url.getPortalObject().campus.students
-        if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
-            letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
-        sid = "%c%d" % (letter,r.randint(99999,1000000))
-        while hasattr(students, sid):
-            sid = "%c%d" % (letter,r.randint(99999,1000000))
-        return sid
-        #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000))
-    ###)
+    #def generateStudentId(self,letter,students = None): ###(
+    #    import random
+    #    r = random
+    #    if students is None:
+    #        students = self.portal_url.getPortalObject().campus.students
+    #    if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
+    #        letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
+    #    sid = "%c%d" % (letter,r.randint(99999,1000000))
+    #    while hasattr(students, sid):
+    #        sid = "%c%d" % (letter,r.randint(99999,1000000))
+    #    return sid
+    #    #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000))
+    ####)
 
 InitializeClass(StudentsFolder)
Index: /WAeUP_SRP/trunk/WAeUPImport.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPImport.py	(revision 4301)
+++ /WAeUP_SRP/trunk/WAeUPImport.py	(revision 4302)
@@ -77,4 +77,5 @@
         self.payments_catalog = waeup_tool.payments_catalog
         self.applicants_catalog = waeup_tool.applicants_catalog
+        self.removed_student_ids = waeup_tool.removed_student_ids
         #self.mode = mode
         # self.import_method = getattr(self, '%s' % mode,None)
@@ -1012,5 +1013,9 @@
                 self.waeup_tool.exportAllStudyLevels(student_id = student_id)
                 # end export
-                students_folder.manage_delObjects((student_id),)         
+                students_folder.manage_delObjects((student_id),)  
+                try:
+                    self.removed_student_ids.addRecord(id = student_id)
+                except:  
+                    msg = "Student already in removed_student_ids"
             else:
                 msg = "Student object not found"
Index: /WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTables.py	(revision 4301)
+++ /WAeUP_SRP/trunk/WAeUPTables.py	(revision 4302)
@@ -1673,13 +1673,17 @@
         course_results = self.course_results.evalAdvancedQuery(query)
         yga1 = 0
+        yg1 = []
         counter1 = 0
         yga2 = 0
+        yg2 = []
         counter2 = 0
         yga3 = 0
+        yg3 = []
         counter3 = 0        
         #import pdb;pdb.set_trace()
         for brain in course_results:
             try:
-                if not float(brain.ca1) + float(brain.ca2) + float(brain.exam) > 0:
+                om = float(brain.ca1) + float(brain.ca2) + float(brain.exam)
+                if not om > 0:
                     continue
                 code = brain.code                
@@ -1694,11 +1698,14 @@
                 if semester == '1':
                     counter1 += 1
-                    yga1 += float(brain.ca1) + float(brain.ca2) + float(brain.exam)
+                    yga1 += om
+                    yg1.append(om)
                 elif semester == '2':
                     counter2 += 1
-                    yga2 += float(brain.ca1) + float(brain.ca2) + float(brain.exam)          
+                    yga2 += om      
+                    yg2.append(om)    
                 if semester == '3':
                     counter3 += 1
-                    yga3 += float(brain.ca1) + float(brain.ca2) + float(brain.exam)
+                    yga3 += om
+                    yg3.append(om)
             except:
                 continue                
@@ -1712,6 +1719,73 @@
             yga3 /= counter3
             yga3 = '%.2f' % yga3                                    
-        return yga1, yga2, yga3, counter1, counter2, counter3
-    ###)
+        return yga1, yga2, yga3, counter1, counter2, counter3, yg1, yg2, yg3
+    ###)
+    
+    
+    #security.declarePublic("calculateCoursePosition")
+    def calculateCoursePosition(self,session_id,level_id,code,score,semester=None):
+        #"""calculate Course Position"""
+        query = Eq('session_id',session_id) & Eq('level_id',level_id) & Eq('code',code)
+        course_results = self.course_results.evalAdvancedQuery(query)
+        ygc = []
+        #import pdb;pdb.set_trace()  
+        for brain in course_results:
+            try:
+                if not float(brain.ca1) + float(brain.ca2) + float(brain.exam) > 0:
+                    continue
+                #code = brain.code   
+                if semester:
+                    res = self.courses_catalog.evalAdvancedQuery(Eq('code',code))
+                    if res:
+                        course = res[0]
+                        # The courses_catalog contains strings and integers in its semester field.
+                        # Maybe this can be fixed by reindexing the catalog. The schema of course says 'CPS Int Field'.
+                        semester_from_course = str(course.semester)
+                    else:
+                        continue
+                    if semester != semester_from_course:
+                        continue
+                ygc.append(float(brain.ca1) + float(brain.ca2) + float(brain.exam))
+            except:
+                continue      
+        ygc.sort(reverse=True)
+        if not len(ygc):
+            return 'no result'
+        #import pdb;pdb.set_trace()        
+        for pos in range(len(ygc)):
+            if ygc[pos] <= float(score):
+                break
+        output = {}   
+        output['pos'] =  '%d of %d' % (pos+1,len(ygc))
+        output['ygc'] = ygc
+        return output
+        
+    security.declareProtected(ModifyPortalContent,"calculateAllCoursePositions")
+    def calculateAllCoursePositions(self,session_id=None):
+        """calculate All Course Positions"""
+        if session_id:
+            query = Eq('session_id',session_id)
+        else:
+            return 'no session_id provided'
+        course_results = self.course_results.evalAdvancedQuery(query)
+        for brain in course_results:
+            try:
+                if not float(brain.ca1) + float(brain.ca2) + float(brain.exam) > 0:
+                    continue
+                res = self.courses_catalog.evalAdvancedQuery(Eq('code',brain.code))
+                if res:
+                    course = res[0]
+                    semester_from_course = str(course.semester)
+                else:
+                    continue                    
+                score = float(brain.ca1) + float(brain.ca2) + float(brain.exam)
+                pic = self.calculateCoursePosition('08',brain.level_id,brain.code,score,semester_from_course)['pos']
+                data = {}
+                data[self.key] = brain.key
+                data['pic'] = pic
+                self.modifyRecord(**data)
+            except:
+                continue                     
+        return 'ready'   
     
     def exportRemoveAllCourses(self,student_id,export=False,remove=False): ###(
@@ -1884,4 +1958,19 @@
 ###)
 
+class RemovedStudentIds(WAeUPTable): ###(
+
+    meta_type = 'WAeUP Removed StudentIds'
+    name = "removed_student_ids"
+    key = "id"
+    def __init__(self,name=None):
+        if name ==  None:
+            name = self.name
+        WAeUPTable.__init__(self, name)
+
+
+InitializeClass(RemovedStudentIds)
+
+###)
+
 # BBB:
 AccomodationTable = AccommodationTable
Index: /WAeUP_SRP/trunk/WAeUPTool.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTool.py	(revision 4301)
+++ /WAeUP_SRP/trunk/WAeUPTool.py	(revision 4302)
@@ -384,7 +384,7 @@
         sid = "%c%d" % (letter,r.randint(99999,1000000))
         students = self.portal_url.getPortalObject().campus.students
-        while self.students_catalog(id = sid) or self.waeup_tool.picturePathExists(sid):
-            if not self.students_catalog(id = sid):
-                logger.info('only picture path %s exists' % sid)
+        while self.students_catalog(id = sid) or self.waeup_tool.picturePathExists(sid) or self.removed_student_ids(id = sid):
+            if self.waeup_tool.picturePathExists(sid):
+                logger.info('picture path %s exists or in ' % sid)
             sid = "%c%d" % (letter,r.randint(99999,1000000))
         return sid
Index: /WAeUP_SRP/trunk/exportimport.py
===================================================================
--- /WAeUP_SRP/trunk/exportimport.py	(revision 4301)
+++ /WAeUP_SRP/trunk/exportimport.py	(revision 4302)
@@ -137,4 +137,5 @@
     importWAeUPTable(site.portal_catalog, '', context,'portal_catalog')
     importWAeUPTable(site.portal_catalog_real, '', context,'portal_catalog_real')
+    importWAeUPTable(site.removed_student_ids, '', context,'removed_student_ids')
 
     site.students_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers',
Index: /WAeUP_SRP/trunk/profiles/default/certificates_catalog.xml
===================================================================
--- /WAeUP_SRP/trunk/profiles/default/certificates_catalog.xml	(revision 4301)
+++ /WAeUP_SRP/trunk/profiles/default/certificates_catalog.xml	(revision 4302)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="catalog.xsl"?>
-<object name="courses_catalog" meta_type="WAeUP Table">
+<object name="certificates_catalog" meta_type="WAeUP Table">
  <column value="code"/>
  <column value="faculty"/>
Index: /WAeUP_SRP/trunk/profiles/default/layouts/application_pume.xml
===================================================================
--- /WAeUP_SRP/trunk/profiles/default/layouts/application_pume.xml	(revision 4301)
+++ /WAeUP_SRP/trunk/profiles/default/layouts/application_pume.xml	(revision 4302)
@@ -1,5 +1,4 @@
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="layout.xsl"?>
-<?xml version="1.0"?>
 <object name="application_pume" meta_type="CPS Layout">
  <property name="layout_create_method"></property>
Index: /WAeUP_SRP/trunk/profiles/default/removed_student_ids.xml
===================================================================
--- /WAeUP_SRP/trunk/profiles/default/removed_student_ids.xml	(revision 4302)
+++ /WAeUP_SRP/trunk/profiles/default/removed_student_ids.xml	(revision 4302)
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>
+<object name="removed_student_ids" meta_type="WAeUP Table">
+ <column value="id"/>
+ <index name="id" meta_type="FieldIndex">
+  <indexed_attr value="id"/>
+ </index>
+</object>
Index: /WAeUP_SRP/trunk/profiles/default/toolset.xml
===================================================================
--- /WAeUP_SRP/trunk/profiles/default/toolset.xml	(revision 4301)
+++ /WAeUP_SRP/trunk/profiles/default/toolset.xml	(revision 4302)
@@ -97,4 +97,6 @@
            class="Products.WAeUP_SRP.WAeUPTables.StudentsCatalog"/>
  <required tool_id="waeup_tool"
-           class="Products.WAeUP_SRP.WAeUPTool.WAeUPTool"/>           
+           class="Products.WAeUP_SRP.WAeUPTool.WAeUPTool"/>         
+ <required tool_id="removed_student_ids"
+           class="Products.WAeUP_SRP.WAeUPTables.RemovedStudentIds"/>             
 </tool-setup>
