Changeset 1716 for WAeUP_SRP/trunk


Ignore:
Timestamp:
26 Apr 2007, 19:48:55 (18 years ago)
Author:
joachim
Message:

events implemented in courses_catalog

Location:
WAeUP_SRP/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/WAeUPTables.py

    r1707 r1716  
    557557    ###)
    558558
    559 
    560559    security.declarePrivate('notify_event_listener') ###(
    561560    def notify_event_listener(self,event_type,object,infos):
    562561        "listen for events"
     562        if not infos.has_key('rpath'):
     563            return
    563564        pt = getattr(object,'portal_type',None)
    564565        mt = getattr(object,'meta_type',None)
     
    573574            students_catalog.modifyRecord(**data)
    574575            return
    575         if pt not in self.affected_types.keys():
    576             return
    577         if not infos.has_key('rpath'):
    578             return
    579576        rpl = infos['rpath'].split('/')
    580577        if pt == 'Student' and event_type == "sys_add_object":
     
    585582                pass
    586583            return
    587         elif pt == 'CourseResult' and mt == 'CPS Proxy Folder':
    588             pass
     584        elif pt == 'StudentCourseResult' and mt == 'CPS Proxy Folder':
     585            if event_type not in ("sys_add_object","sys_del_object"):
     586                return
     587            #from pdb import set_trace;set_trace()
     588            course_id = object.getId()
     589            student_id = object.absolute_url_path().split('/')[-4]
     590            res = self(id = student_id)
     591            if not res:
     592                return
     593            student_rec = res[0]
     594            registered_courses = student_rec.registered_courses
     595            if event_type == "sys_add_object":
     596                registered_courses.append(course_id)
     597            if event_type == "sys_del_object":
     598                registered_courses.remove(course_id)
     599            data['id'] = student_id
     600            data['registered_courses'] = registered_courses
     601            self.modifyRecord(**data)
     602        if pt not in self.affected_types.keys():
     603            return
    589604        if event_type not in ('sys_modify_object'):
    590             #from pdb import set_trace;set_trace()
    591605            return
    592606        if mt == 'CPS Proxy Folder':
    593607            return
    594         for field in self.affected_types[pt]:
     608        for field in self.affected_types[pt]['fields']:
    595609            if hasattr(self,'get_from_doc_%s' % field):
    596610                data[field] = getattr(self,'get_from_doc_%s' % field)(object)
     
    598612                data[field] = getattr(object,field)
    599613        data['id'] = rpl[2]
    600         students_catalog.modifyRecord(**data)
     614        self.modifyRecord(**data)
    601615    ###)
    602616
     
    607621
    608622class CoursesCatalog(WAeUPTable): ###(
     623    security = ClassSecurityInfo()
    609624
    610625    meta_type = 'WAeUP Courses Catalog'
     
    614629        WAeUPTable.__init__(self, 'courses_catalog')
    615630
     631    def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###(
     632        """ clear the catalog, then re-index everything """
     633
     634        elapse = time.time()
     635        c_elapse = time.clock()
     636
     637        pgthreshold = self._getProgressThreshold()
     638        handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None
     639        self.refreshCatalog(clear=1, pghandler=handler)
     640
     641        elapse = time.time() - elapse
     642        c_elapse = time.clock() - c_elapse
     643
     644        RESPONSE.redirect(
     645            URL1 +
     646            '/manage_catalogAdvanced?manage_tabs_message=' +
     647            urllib.quote('Catalog Updated \n'
     648                         'Total time: %s\n'
     649                         'Total CPU time: %s' % (`elapse`, `c_elapse`)))
     650    ###)
     651
     652    def reindexIndex(self, name, REQUEST,pghandler=None): ###(
     653        if isinstance(name, str):
     654            name = (name,)
     655        courses = self.portal_catalog(portal_type="Course")
     656        num_objects = len(courses)
     657        if pghandler:
     658            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
     659        for i in xrange(num_objects):
     660            if pghandler: pghandler.report(i)
     661            course_brain = courses[i]
     662            course_object = course_brain.getObject()
     663            pl = course_brain.getPath().split('/')
     664            data = {}
     665            cid = data[self.key] = course_brain.getId
     666            data['faculty'] = pl[-4]
     667            data['department'] = pl[-3]
     668            doc = course_object.getContent()
     669            for field in name:
     670                if field not in (self.key,'faculty','department'):
     671                    data[field] = getattr(doc,field)
     672            self.modifyRecord(**data)
     673        if pghandler: pghandler.finish()
     674    ###)
     675
     676    def refreshCatalog(self, clear=0, pghandler=None): ###(
     677        """ re-index everything we can find """
     678        courses = self.portal_catalog(portal_type="Course")
     679        num_objects = len(courses)
     680        if pghandler:
     681            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
     682        for i in xrange(num_objects):
     683            if pghandler: pghandler.report(i)
     684            course_brain = courses[i]
     685            course_object = course_brain.getObject()
     686            pl = course_brain.getPath().split('/')
     687            data = {}
     688            data[self.key] = course_brain.getId
     689            data['faculty'] = pl[-4]
     690            data['department'] = pl[-3]
     691            doc = course_object.getContent()
     692            self.modifyRecord(**data)
     693        if pghandler: pghandler.finish()
     694    ###)
     695
     696    security.declarePrivate('notify_event_listener') ###(
     697    def notify_event_listener(self,event_type,object,infos):
     698        "listen for events"
     699        if not infos.has_key('rpath'):
     700            return
     701        pt = getattr(object,'portal_type',None)
     702        mt = getattr(object,'meta_type',None)
     703        if pt != 'Course':
     704            return
     705        #from pdb import set_trace;set_trace()
     706        data = {}
     707        rpl = infos['rpath'].split('/')
     708        if event_type not in ("sys_add_object","sys_modify_object","sys_del_object"):
     709            return
     710        course_id = object.getId()
     711        data[self.key] = course_id
     712        if event_type == "sys_add_object":
     713            try:
     714                self.addRecord(**data)
     715            except ValueError:
     716                pass
     717        if event_type == "sys_del_object":
     718            self.deleteRecord(course_id)
     719        if event_type == "sys_modify_object" and mt == 'Course':
     720            for field in self.schema():
     721                data[field] = getattr(object,field,None)
     722            course_id = object.aq_parent.getId()
     723            data[self.key] = course_id
     724            self.modifyRecord(**data)
     725    ###)
     726
    616727
    617728InitializeClass(CoursesCatalog)
  • WAeUP_SRP/trunk/WAeUPTool.py

    r1707 r1716  
    6868        response.write("%s<br />\r\n" % s)
    6969
     70    security.declareProtected(ModifyPortalContent,'openLog')
     71    def openLog(self,name):
     72        """open a log file"""
     73        version = 1
     74        path = "%s/log/%s_%d.log" % (i_home,name,version)
     75        while os.path.exists(path):
     76            version += 1
     77            path = "%s/log/%s_%d.log" % (i_home,name,version)
     78        log = open(path,"w")
     79        return log
     80
     81    security.declareProtected(ModifyPortalContent,'writeLog')
     82    def writeLog(self,logfile,s):
     83        """write to the log file"""
     84        logfile.write(s)
     85
     86       
    7087    def generateStudentId(self,letter): ###(
    7188        import random
  • WAeUP_SRP/trunk/profiles/default/courses_catalog.xml

    r1410 r1716  
    66 <column value="department"/>
    77 <column value="title"/>
    8  <column value="level"/>
    98 <column value="credits"/>
    109 <column value="passmark"/>
     
    1918  <indexed_attr value="department"/>
    2019 </index>
    21  <index name="level" meta_type="KeywordIndex">
    22   <indexed_attr value="level"/>
    23  </index>
    2420</object>
  • WAeUP_SRP/trunk/skins/waeup_default/waeup_document_create_do.py

    r1366 r1716  
    3434if new_id is not None:
    3535    id = new_id
    36 if type_name == "Course":
     36if type_name == "Course": # disable if  handled by event
    3737    d = {}
    3838    ptl = request.get('PATH_TRANSLATED').split('/')
  • WAeUP_SRP/trunk/skins/waeup_default/waeup_edit.py

    r1571 r1716  
    102102                                             )
    103103        logger.info('%s edited %s of %s' % (member,context.id,student_id))
    104     elif context.portal_type == "Course":
     104    elif context.portal_type == "Course": # disable if handled by events
    105105        dd = {}
    106106        dd.update(ds) # ds is not a real dictionary
Note: See TracChangeset for help on using the changeset viewer.