#-*- mode: python; mode: fold -*- # (C) Copyright 2005 AixtraWare # Author: Joachim Schmitz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as published # by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # # $Id: WAeUPTables.py 2084 2007-08-03 05:58:51Z joachim $ from zope.interface import implements from Globals import InitializeClass from Products.ZCatalog.ZCatalog import ZCatalog from Products.ZCatalog.ProgressHandler import ZLogHandler from AccessControl import ClassSecurityInfo from Products.CMFCore.permissions import ModifyPortalContent import urllib import DateTime,time import csv,re import logging import Globals p_home = Globals.package_home(globals()) i_home = Globals.INSTANCE_HOME from Products.CMFCore.CatalogTool import CatalogTool from Products.AdvancedQuery import Eq, Between, Le,In ADDING_SHEDULED = "adding_sheduled" OBJECT_CREATED = "object_created" from interfaces import IWAeUPTable class AttributeHolder(object): pass def dict2ob(dict): ob = AttributeHolder() for key, value in dict.items(): setattr(ob, key, value) return ob class WAeUPTable(ZCatalog): ###( implements(IWAeUPTable) security = ClassSecurityInfo() def refreshCatalog(self, clear=0, pghandler=None): """ don't refresh for a normal table """ if self.REQUEST and self.REQUEST.RESPONSE: self.REQUEST.RESPONSE.redirect( URL1 + '/manage_catalogAdvanced?manage_tabs_message=Catalog%20refresh%20not%20implemented') def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): """ clears the whole enchilada """ #if REQUEST and RESPONSE: # RESPONSE.redirect( # URL1 + # '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Clearing%20disabled') self._catalog.clear() if REQUEST and RESPONSE: RESPONSE.redirect( URL1 + '/manage_catalogAdvanced?manage_tabs_message=Catalog%20cleared') def addRecord(self, **data): # The uid is the same as "bed". uid = data[self.key] res = self.searchResults({"%s" % self.key : uid}) if len(res) > 0: raise ValueError("More than one record with uid %s" % uid) self.catalog_object(dict2ob(data), uid=uid) return uid def deleteRecord(self, uid): self.uncatalog_object(uid) def searchAndSetRecord(self, **data): raise NotImplemented def modifyRecord(self, record=None, **data): #records = self.searchResults(uid=uid) uid = data[self.key] if record is None: records = self.searchResults({"%s" % self.key : uid}) if len(records) > 1: # Can not happen, but anyway... raise ValueError("More than one record with uid %s" % uid) if len(records) == 0: raise KeyError("No record for uid %s" % uid) record = records[0] record_data = {} for field in self.schema() + self.indexes(): record_data[field] = getattr(record, field) # Add the updated data: record_data.update(data) self.catalog_object(dict2ob(record_data), uid) def reindexIndex(self, name, REQUEST,pghandler=None): if isinstance(name, str): name = (name,) paths = self._catalog.uids.items() i = 0 #import pdb;pdb.set_trace() for p,rid in paths: i += 1 metadata = self.getMetadataForRID(rid) record_data = {} for field in name: record_data[field] = metadata.get(field) uid = metadata.get(self.key) self.catalog_object(dict2ob(record_data), uid, idxs=name, update_metadata=0) security.declareProtected(ModifyPortalContent,"exportAllRecords") def exportAllRecords(self): "export a WAeUPTable" #import pdb;pdb.set_trace() fields = [field for field in self.schema()] format = ','.join(['"%%(%s)s"' % fn for fn in fields]) csv = [] csv.append(','.join(['"%s"' % fn for fn in fields])) for uid in self._catalog.uids: records = self.searchResults({"%s" % self.key : uid}) if len(records) > 1: # Can not happen, but anyway... raise ValueError("More than one record with uid %s" % uid) if len(records) == 0: raise KeyError("No record for uid %s" % uid) rec = records[0] csv.append(format % rec) current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") open("%s/import/%s-%s.csv" % (i_home,self.getId(),current),"w+").write('\n'.join(csv)) ###) class AccommodationTable(WAeUPTable): ###( meta_type = 'WAeUP Accommodation Tool' name = "accommodation" key = "bed" def __init__(self): WAeUPTable.__init__(self, 'portal_accommodation') def searchAndReserveBed(self, student_id,bed_type): records = self.searchResults({'student' : student_id}) if len(records) > 0: return -1,"Student with Id %s already booked bed %s." % (student_id,records[0].bed) records = [r for r in self.searchResults({'bed_type' : bed_type}) if not r.student] #import pdb;pdb.set_trace() if len(records) == 0: return -2,"No bed available" rec = records[0] self.modifyRecord(bed=rec.bed,student=student_id) s_logger = logging.getLogger('WAeUPTables.AccommodationTable.searchAndReserveBed') s_logger.info('%s reserved bed %s' % (student_id,rec.bed)) return 1,rec.bed InitializeClass(AccommodationTable) ###) class PinTable(WAeUPTable): ###( from ZODB.POSException import ConflictError meta_type = 'WAeUP Pin Tool' name = "pins" key = 'pin' def __init__(self): WAeUPTable.__init__(self, 'portal_pins') def searchAndSetRecord(self, uid, student_id,prefix): #records = self.searchResults(uid=uid) records = self.searchResults(student = student_id) #import pdb;pdb.set_trace() if len(records) > 0 and prefix in ('CLR','APP'): for r in records: if r.pin != uid and r.prefix_batch.startswith(prefix): return -2 records = self.searchResults({"%s" % self.key : uid}) if len(records) > 1: # Can not happen, but anyway... raise ValueError("More than one record with uid %s" % uid) if len(records) == 0: return -1 record = records[0] if record.student == "": record_data = {} for field in self.schema() + self.indexes(): record_data[field] = getattr(record, field) # Add the updated data: record_data['student'] = student_id try: self.catalog_object(dict2ob(record_data), uid) return 1 except ConflictError: return 2 if record.student.upper() != student_id.upper(): return 0 if record.student.upper() == student_id.upper(): return 2 return -3 InitializeClass(PinTable) ###) class PumeResultsTable(WAeUPTable): ###( meta_type = 'WAeUP PumeResults Tool' name = "pumeresults" key = "jamb_reg_no" def __init__(self): WAeUPTable.__init__(self, 'portal_pumeresults') InitializeClass(PumeResultsTable) ###) class StudentsCatalog(WAeUPTable): ###( security = ClassSecurityInfo() meta_type = 'WAeUP Students Catalog' name = "students_catalog" key = "id" affected_types = { ###( 'StudentApplication': {'id': 'application', 'fields': ('jamb_reg_no', 'entry_mode', #'entry_level', 'entry_session', ) }, 'StudentClearance': {'id': 'clearance', 'fields': ('matric_no', 'lga', ) }, 'StudentPersonal': {'id': 'personal', 'fields': ('name', 'sex', 'perm_address', 'email', 'phone', ) }, 'StudentStudyCourse': {'id': 'study_course', 'fields': ('course', # study_course 'faculty', # from certificate 'department', # from certificate 'end_level', # from certificate 'level', # current_level 'mode', # current_mode 'session', # current_session 'verdict', # current_verdict ) }, } ###) def __init__(self): WAeUPTable.__init__(self, 'students_catalog') return def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): """ clears the whole enchilada """ self._catalog.clear() if REQUEST and RESPONSE: RESPONSE.redirect( URL1 + '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared') def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( """ clear the catalog, then re-index everything """ elapse = time.time() c_elapse = time.clock() pgthreshold = self._getProgressThreshold() handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None self.refreshCatalog(clear=1, pghandler=handler) elapse = time.time() - elapse c_elapse = time.clock() - c_elapse RESPONSE.redirect( URL1 + '/manage_catalogAdvanced?manage_tabs_message=' + urllib.quote('Catalog Updated \n' 'Total time: %s\n' 'Total CPU time: %s' % (`elapse`, `c_elapse`))) ###) 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: return None return certificate_res[0].getPath().split('/')[-3] 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: return None return certificate_res[0].getPath().split('/')[-4] 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: return None return getattr(certificate_res[0].getObject().getContent(),'end_level','unknown') def get_from_doc_level(self,doc,cached_data={}): "return the students level" if doc is None: return None return getattr(doc,'current_level',None) def get_from_doc_mode(self,doc,cached_data={}): "return the students mode" if doc is None: return None cm = getattr(doc,'current_mode',None) return cm def get_from_doc_session(self,doc,cached_data={}): "return the students current_session" if doc is None: return None return getattr(doc,'current_session',None) def get_from_doc_entry_session(self,doc,cached_data={}): "return the students entry_session" if doc is None: return None es = getattr(doc,'entry_session',None) if es is not None and len(es) == 2: return es try: digit = int(doc.jamb_reg_no[0]) except: return "-1" if digit < 8: return "0%c" % doc.jamb_reg_no[0] return "9%c" % doc.jamb_reg_no[0] def get_from_doc_course(self,doc,cached_data={}): "return the students study_course" if doc is None: return None return getattr(doc,'study_course',None) def get_from_doc_name(self,doc,cached_data={}): "return the students name from the personal" if doc is None: return None return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname) def get_from_doc_verdict(self,doc,cached_data={}): "return the students study_course" if doc is None: return None return getattr(doc,'current_verdict',None) ###) def reindexIndex(self, name, REQUEST,pghandler=None): ###( if isinstance(name, str): name = (name,) reindextypes = {} reindex_special = [] for n in name: if n in ("review_state","registered_courses"): reindex_special.append(n) else: for pt in self.affected_types.keys(): if n in self.affected_types[pt]['fields']: if reindextypes.has_key(pt): reindextypes[pt].append(n) else: 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'): aq_portal = self.portal_catalog_real.evalAdvancedQuery else: aq_portal = self.portal_catalog.evalAdvancedQuery num_objects = len(students) if pghandler: pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) noattr = set(('StudentClearance','StudentPersonal')) & set(reindextypes.keys()) #import pdb;pdb.set_trace() for i in xrange(num_objects): if pghandler: pghandler.report(i) student_brain = students[i] student_object = student_brain.getObject() # query = Eq('path',student_brain.getPath()) # sub_brains_list = aq_portal(query) # sub_brains = {} # for sub_brain in sub_brains_list: # sub_brains[sub_brain.portal_type] = sub_brain # student_path = student_brain.getPath() data = {} modified = False sid = data['id'] = student_brain.getId if reindex_special and 'review_state' in reindex_special: modified = True data['review_state'] = student_brain.review_state sub_objects = False for pt in reindextypes.keys(): modified = True try: doc = getattr(student_object,self.affected_types[pt]['id']).getContent() #doc = sub_brains[pt].getObject().getContent() # path = "%s/%s" % (student_path,self.affected_types[pt]['id']) # doc = self.unrestrictedTraverse(path).getContent() sub_objects = True except: continue for field in set(name).intersection(self.affected_types[pt]['fields']): if hasattr(self,'get_from_doc_%s' % field): data[field] = getattr(self,'get_from_doc_%s' % field)(doc, cached_data=cached_data) else: data[field] = getattr(doc,field) if not sub_objects and noattr: import_res = self.returning_import(id = sid) if not import_res: continue import_record = import_res[0] data['matric_no'] = import_record.matric_no data['sex'] = import_record.Sex == 'F' data['name'] = "%s %s %s" % (import_record.Firstname, import_record.Middlename, import_record.Lastname) data['jamb_reg_no'] = import_record.Entryregno if reindex_special and 'registered_courses' in reindex_special: try: study_course = getattr(student_object,"study_course") level_ids = study_course.objectIds() except: continue if not level_ids: continue modified = True level_ids.sort() course_ids = getattr(study_course,level_ids[-1]).objectIds() courses = [] for c in course_ids: if c.endswith('_co'): courses.append(c[:-3]) else: courses.append(c) data['registered_courses'] = courses if modified: self.modifyRecord(**data) if pghandler: pghandler.finish() ###) def refreshCatalog(self, clear=0, pghandler=None): ###( """ re-index everything we can find """ students_folder = self.portal_url.getPortalObject().campus.students if clear: self._catalog.clear() 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) for i in xrange(num_objects): if pghandler: pghandler.report(i) student_brain = students[i] spath = student_brain.getPath() student_object = student_brain.getObject() data = {} sid = data['id'] = student_brain.getId data['review_state'] = student_brain.review_state sub_objects = False for pt in self.affected_types.keys(): modified = True try: doc = getattr(student_object,self.affected_types[pt]['id']).getContent() sub_objects = True except: #from pdb import set_trace;set_trace() continue 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, cached_data=cached_data) else: data[field] = getattr(doc,field,None) if not sub_objects: import_res = self.returning_import(id = sid) if not import_res: continue import_record = import_res[0] data['matric_no'] = import_record.matric_no data['sex'] = import_record.Sex == 'F' data['name'] = "%s %s %s" % (import_record.Firstname, import_record.Middlename, import_record.Lastname) data['jamb_reg_no'] = import_record.Entryregno else: study_course = getattr(student_object,'study_course',None) current_level = data.get('level',None) data['registered_courses'] = [] if study_course and current_level and current_level in study_course.objectIds(): level_obj = getattr(study_course,current_level) courses = [] for c in level_obj.objectIds(): if c.endswith('_co'): courses.append(c[:-3]) else: courses.append(c) data['registered_courses'] = courses self.addRecord(**data) if pghandler: pghandler.finish() ###) security.declarePrivate('notify_event_listener') ###( def notify_event_listener(self,event_type,object,infos): "listen for events" if not infos.has_key('rpath'): return pt = getattr(object,'portal_type',None) mt = getattr(object,'meta_type',None) students_catalog = self data = {} if pt == 'Student' and\ mt == 'CPS Proxy Folder' and\ event_type.startswith('workflow'): data['id'] = object.getId() data['review_state'] = self.portal_workflow.getInfoFor(object,'review_state',None) students_catalog.modifyRecord(**data) return rpl = infos['rpath'].split('/') if pt == 'Student' and mt == 'CPS Proxy Folder'\ and event_type == "sys_add_object": student_id = object.id try: self.addRecord(id = student_id) except ValueError: pass return elif pt == 'StudentCourseResult' and mt == 'CPS Proxy Folder': if event_type not in ("sys_add_object","sys_del_object"): return level_session = getattr(object.aq_parent.getContent(),'session','unknown') if level_session not in (self.getSessionId()[-2:],'2006/2007'): return course_id = object.getId() if course_id.endswith('_co'): course_id = course_id[:-3] student_id = object.absolute_url_path().split('/')[-4] res = students_catalog(id = student_id) if not res: return student_rec = res[0] registered_courses = getattr(student_rec,'registered_courses',None) if not registered_courses: registered_courses = [] #import pdb;pdb.set_trace() if event_type == "sys_add_object": if course_id not in registered_courses: registered_courses.append(course_id) else: return elif registered_courses and event_type == "sys_del_object": removed = False while course_id in registered_courses: removed = True registered_courses.remove(course_id) if not removed: return data['id'] = student_id data['registered_courses'] = registered_courses self.modifyRecord(record = student_rec, **data) return if pt not in self.affected_types.keys(): return if event_type not in ('sys_modify_object'): return if mt == 'CPS Proxy Folder': return 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)(object) else: data[field] = getattr(object,field) data['id'] = rpl[2] self.modifyRecord(**data) ###) InitializeClass(StudentsCatalog) ###) class CoursesCatalog(WAeUPTable): ###( security = ClassSecurityInfo() meta_type = 'WAeUP Courses Catalog' name = "courses_catalog" key = "code" def __init__(self): WAeUPTable.__init__(self, 'courses_catalog') def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( """ clear the catalog, then re-index everything """ elapse = time.time() c_elapse = time.clock() pgthreshold = self._getProgressThreshold() handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None self.refreshCatalog(clear=1, pghandler=handler) elapse = time.time() - elapse c_elapse = time.clock() - c_elapse RESPONSE.redirect( URL1 + '/manage_catalogAdvanced?manage_tabs_message=' + urllib.quote('Catalog Updated \n' 'Total time: %s\n' 'Total CPU time: %s' % (`elapse`, `c_elapse`))) ###) def reindexIndex(self, name, REQUEST,pghandler=None): ###( if isinstance(name, str): name = (name,) courses = self.portal_catalog(portal_type="Course") num_objects = len(courses) if pghandler: pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) for i in xrange(num_objects): if pghandler: pghandler.report(i) course_brain = courses[i] course_object = course_brain.getObject() pl = course_brain.getPath().split('/') data = {} cid = data[self.key] = course_brain.getId data['faculty'] = pl[-4] data['department'] = pl[-3] doc = course_object.getContent() for field in name: if field not in (self.key,'faculty','department'): data[field] = getattr(doc,field) self.modifyRecord(**data) if pghandler: pghandler.finish() ###) def refreshCatalog(self, clear=0, pghandler=None): ###( """ re-index everything we can find """ if clear: self._catalog.clear() courses = self.portal_catalog(portal_type="Course") num_objects = len(courses) if pghandler: pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) #from pdb import set_trace;set_trace() for i in xrange(num_objects): if pghandler: pghandler.report(i) course_brain = courses[i] course_doc = course_brain.getObject().getContent() pl = course_brain.getPath().split('/') data = {} for field in self.schema(): data[field] = getattr(course_doc,field,None) data[self.key] = course_brain.getId ai = pl.index('academics') data['faculty'] = pl[ai +1] data['department'] = pl[ai +2] if clear: self.addRecord(**data) else: self.modifyRecord(**data) if pghandler: pghandler.finish() ###) security.declarePrivate('notify_event_listener') ###( def notify_event_listener(self,event_type,object,infos): "listen for events" if not infos.has_key('rpath'): return pt = getattr(object,'portal_type',None) mt = getattr(object,'meta_type',None) if pt != 'Course': return data = {} rpl = infos['rpath'].split('/') if event_type not in ("sys_add_object","sys_modify_object","sys_del_object"): return course_id = object.getId() data[self.key] = course_id if event_type == "sys_add_object" and mt == 'CPS Proxy Folder': try: self.addRecord(**data) except ValueError: return course_id = object.getId() doc = object.getContent() if doc is None: return for field in self.schema(): data[field] = getattr(doc,field,None) data[self.key] = course_id ai = rpl.index('academics') data['faculty'] = rpl[ai +1] data['department'] = rpl[ai +2] self.modifyRecord(**data) return if event_type == "sys_del_object": self.deleteRecord(course_id) return if event_type == "sys_modify_object" and mt == 'Course': #from pdb import set_trace;set_trace() for field in self.schema(): data[field] = getattr(object,field,None) course_id = object.aq_parent.getId() data[self.key] = course_id ai = rpl.index('academics') data['faculty'] = rpl[ai +1] data['department'] = rpl[ai +2] self.modifyRecord(**data) ###) InitializeClass(CoursesCatalog) ###) class CourseResults(WAeUPTable): ###( security = ClassSecurityInfo() meta_type = 'WAeUP Results Catalog' name = "course_results" key = "key" #student_id + level + course_id def __init__(self): WAeUPTable.__init__(self, 'course_results') self._queue = [] def addRecord(self, **data): ###( # The uid is the same as "bed". uid = key = "%(student_id)s|%(level_id)s|%(course_id)s" % data if key in self._queue: return uid data['queue_status'] = ADDING_SHEDULED data['%s' % self.key] = uid res = self.searchResults({"%s" % self.key : uid}) if len(res) > 0: raise ValueError("More than one record with uid %s" % uid) self.catalog_object(dict2ob(data), uid=uid) if not hasattr(self,'_queue'): self._queue = [] self._queue.append(key) self._p_changed = 1 return uid ###) def deleteRecord(self, uid): ###( self.uncatalog_object(uid) if uid in self._queue: self._queue.remove(uid) ###) def getCourses(self,student_id,level_id): ###( query = Eq('student_id',student_id) & Eq('level_id', level_id) carry_overs = [] normal = [] credits = 0 for brain in self.course_results.evalAdvancedQuery(query): d = {} credits += int(brain.credits) for field in self.schema(): d[field] = getattr(brain,field,'') d['sheduled'] = brain.queue_status == ADDING_SHEDULED d['coe'] = 'Elective' if brain.core_or_elective: d['coe'] = 'Core' d['title'] = self.courses_catalog.evalAdvancedQuery(Eq('code',brain.code))[0].title if brain.code.endswith('_co'): carry_overs.append(d) else: normal.append(d) normal.sort(cmp=lambda x,y: cmp(x['semester'], y['semester'])) carry_overs.sort(cmp=lambda x,y: cmp(x['semester'], y['semester'])) return credits,carry_overs,normal ###) def addObject(self,record): ###( key = record.key student_id,level_id,course_id = key.split('|') level = getattr(getattr(self.portal_url.getPortalObject().campus.students,student_id).study_course,level_id) cr_id = level.invokeFactory('StudentCourseResult', course_id) course_result = getattr(level,cr_id) self.portal_workflow.doActionFor(course_result,'open') d = {} for field in self.schema(): d[field] = getattr(record,field,'') course_result.getContent().edit(mapping=d) ###) security.declareProtected(ModifyPortalContent,"process_queue") ###( def process_queue(self,limit=None): """adds objects and removes them from the queue. If limit is specified, at most (limit) events are removed. """ if not hasattr(self,'_queue'): return 0 queue= self._queue if not limit or len(queue) <= limit: keys = self._queue[:] else: keys = queue[:limit] if not keys: records = self.evalAdvancedQuery(Eq('queue_status',ADDING_SHEDULED)) else: records = self.evalAdvancedQuery(In("%s" % self.key,keys)) for record in records: if record.queue_status == OBJECT_CREATED: continue self.addObject(record) data = {} data['key'] = record.key data['queue_status'] = OBJECT_CREATED self.modifyRecord(**data) count = 0 for key in keys: count +=1 if key in self._queue: self._queue.remove(key) self._p_changed = 1 return count,len(self._queue) ###) def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): ###( """ clears the whole enchilada """ self._catalog.clear() if REQUEST and RESPONSE: RESPONSE.redirect( URL1 + '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared') ###) def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( """ clear the catalog, then re-index everything """ elapse = time.time() c_elapse = time.clock() pgthreshold = self._getProgressThreshold() handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None self.refreshCatalog(clear=1, pghandler=handler) elapse = time.time() - elapse c_elapse = time.clock() - c_elapse RESPONSE.redirect( URL1 + '/manage_catalogAdvanced?manage_tabs_message=' + urllib.quote('Catalog Updated \n' 'Total time: %s\n' 'Total CPU time: %s' % (`elapse`, `c_elapse`))) ###) def refreshCatalog(self, clear=1, pghandler=None): ###( """ re-index everything we can find """ students_folder = self.portal_url.getPortalObject().campus.students if clear: self._catalog.clear() course_results = self.portal_catalog(portal_type="StudentCourseResult") num_objects = len(course_results) if pghandler: pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) #import pdb;pdb.set_trace() for i in xrange(num_objects): if pghandler: pghandler.report(i) course_result_brain = course_results[i] path_list = course_result_brain.getPath().split('/') course_result_object = course_result_brain.getObject() course_result_doc = course_result_object.getContent() data = {} level_id = path_list[-2] course_id = path_list[-1] student_id = path_list[-4] for field in self.schema(): data[field] = getattr(course_result_doc,field,'') data['key'] = key = "%(student_id)s|%(level_id)s|%(course_id)s" % vars() data['student_id'] = student_id data['level_id'] = level_id data['queue_status'] = OBJECT_CREATED self.catalog_object(dict2ob(data), uid=key) if pghandler: pghandler.finish() ###) security.declarePrivate('notify_event_listener') ###( def notify_event_listener(self,event_type,object,infos): "listen for events" if not infos.has_key('rpath'): return pt = getattr(object,'portal_type',None) mt = getattr(object,'meta_type',None) data = {} rpl = infos['rpath'].split('/') if mt == 'CPS Proxy Folder': return if pt == 'StudentCourseResult' and event_type == "sys_modify_object": data["%s" % self.key] = uid = "%s|%s|%s" % (rpl[-5],rpl[-3],rpl[-2]) records = self.searchResults({"%s" % self.key : uid}) if len(records) > 1: # Can not happen, but anyway... raise ValueError("More than one record with uid %s" % uid) if len(records) == 0: raise KeyError("No record for uid %s" % uid) record = records[0] #import pdb;pdb.set_trace() for field in ('core_or_elective','score'): value = getattr(object,field,None) data[field] = value self.modifyRecord(record,**data) ###) InitializeClass(CourseResults) ###) class OnlinePaymentsImport(WAeUPTable): ###( meta_type = 'WAeUP Online Payment Transactions' name = "online_payments_import" key = "order_id" def __init__(self): WAeUPTable.__init__(self, self.name) InitializeClass(OnlinePaymentsImport) ###) class ReturningImport(WAeUPTable): ###( meta_type = 'Returning Import Table' name = "returning_import" key = "matric_no" def __init__(self): WAeUPTable.__init__(self, 'returning_import') InitializeClass(ReturningImport) ###) class ResultsImport(WAeUPTable): ###( meta_type = 'Results Import Table' name = "results_import" key = "key" def __init__(self): WAeUPTable.__init__(self, 'results_import') InitializeClass(ResultsImport) ###) class PaymentsCatalog(WAeUPTable): ###( meta_type = 'WAeUP Payments Catalog' name = "students_catalog" key = "id" def __init__(self): WAeUPTable.__init__(self, 'payments_catalog') InitializeClass(PaymentsCatalog) ###) # BBB: AccomodationTable = AccommodationTable