Index: /WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTables.py	(revision 2077)
+++ /WAeUP_SRP/trunk/WAeUPTables.py	(revision 2078)
@@ -313,8 +313,24 @@
     ###)
 
-    def get_from_doc_department(self,doc): ###(
+    def fill_certificates_dict(self):
+        "return certificate data in  dict"
+        certificates_brains = self.portal_catalog(portal_type ='Certificate')
+        d = {}
+        for cb in certificates_brains:
+            certificate_doc = cb.getObject().getContent()
+            cb_path = cb.getPath().split('/')
+            ld = {}
+            ld['faculty'] = cb_path[-4]
+            ld['department'] = cb_path[-3]
+            ld['end_level'] = getattr(certificate_doc,'end_level','999')
+            d[cb.getId] = ld
+        return d
+            
+    def get_from_doc_department(self,doc,cached_data={}): ###(
         "return the students department"
         if doc is None:
             return None
+        if cached_data.has_key(doc.study_course):
+            return cached_data[doc.study_course]['department']
         certificate_res = self.portal_catalog(id = doc.study_course)
         if len(certificate_res) != 1:
@@ -322,8 +338,10 @@
         return certificate_res[0].getPath().split('/')[-3]
 
-    def get_from_doc_faculty(self,doc):
+    def get_from_doc_faculty(self,doc,cached_data={}):
         "return the students faculty"
         if doc is None:
             return None
+        if cached_data.has_key(doc.study_course):
+            return cached_data[doc.study_course]['faculty']
         certificate_res = self.portal_catalog(id = doc.study_course)
         if len(certificate_res) != 1:
@@ -331,8 +349,10 @@
         return certificate_res[0].getPath().split('/')[-4]
 
-    def get_from_doc_end_level(self,doc): ###(
+    def get_from_doc_end_level(self,doc,cached_data={}): 
         "return the students end_level"
         if doc is None:
             return None
+        if cached_data.has_key(doc.study_course):
+            return cached_data[doc.study_course]['end_level']
         certificate_res = self.portal_catalog(id = doc.study_course)
         if len(certificate_res) != 1:
@@ -340,5 +360,5 @@
         return getattr(certificate_res[0].getObject().getContent(),'end_level','unknown')
 
-    def get_from_doc_level(self,doc):
+    def get_from_doc_level(self,doc,cached_data={}):
         "return the students level"
         if doc is None:
@@ -346,5 +366,5 @@
         return getattr(doc,'current_level',None)
 
-    def get_from_doc_mode(self,doc):
+    def get_from_doc_mode(self,doc,cached_data={}):
         "return the students mode"
         if doc is None:
@@ -354,5 +374,5 @@
 
 
-    def get_from_doc_session(self,doc):
+    def get_from_doc_session(self,doc,cached_data={}):
         "return the students current_session"
         if doc is None:
@@ -360,5 +380,5 @@
         return getattr(doc,'current_session',None)
 
-    def get_from_doc_entry_session(self,doc):
+    def get_from_doc_entry_session(self,doc,cached_data={}):
         "return the students entry_session"
         if doc is None:
@@ -375,5 +395,5 @@
         return "9%c" % doc.jamb_reg_no[0]
 
-    def get_from_doc_course(self,doc):
+    def get_from_doc_course(self,doc,cached_data={}):
         "return the students study_course"
         if doc is None:
@@ -381,5 +401,5 @@
         return getattr(doc,'study_course',None)
 
-    def get_from_doc_name(self,doc):
+    def get_from_doc_name(self,doc,cached_data={}):
         "return the students name from the personal"
         if doc is None:
@@ -387,5 +407,5 @@
         return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname)
 
-    def get_from_doc_verdict(self,doc):
+    def get_from_doc_verdict(self,doc,cached_data={}):
         "return the students study_course"
         if doc is None:
@@ -410,4 +430,7 @@
                             reindextypes[pt]= [n]
                         break
+        cached_data = {}
+        if set(name).intersection(set(('faculty','department','end_level'))):
+            cached_data = self.fill_certificates_dict()
         students = self.portal_catalog(portal_type="Student")
         if hasattr(self,'portal_catalog_real'):
@@ -439,5 +462,6 @@
                 for field in self.affected_types[pt]['fields']:
                     if hasattr(self,'get_from_doc_%s' % field):
-                        data[field] = getattr(self,'get_from_doc_%s' % field)(doc)
+                        data[field] = getattr(self,'get_from_doc_%s' % field)(doc,
+                                                                              cached_data=cached_data)
                     else:
                         data[field] = getattr(doc,field)
@@ -483,4 +507,5 @@
         students = self.portal_catalog(portal_type="Student")
         num_objects = len(students)
+        cached_data = self.fill_certificates_dict()
         if pghandler:
             pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
@@ -504,5 +529,6 @@
                 for field in self.affected_types[pt]['fields']:
                     if hasattr(self,'get_from_doc_%s' % field):
-                        data[field] = getattr(self,'get_from_doc_%s' % field)(doc)
+                        data[field] = getattr(self,'get_from_doc_%s' % field)(doc,
+                                                                              cached_data=cached_data)
                     else:
                         data[field] = getattr(doc,field,None)
