Changeset 1724


Ignore:
Timestamp:
30 Apr 2007, 15:37:48 (18 years ago)
Author:
joachim
Message:

improve or fix id_rename and catalog handling

Location:
WAeUP_SRP/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/WAeUPTables.py

    r1722 r1724  
    475475        """ re-index everything we can find """
    476476        students_folder = self.portal_url.getPortalObject().campus.students
    477 
    478         cat = self._catalog
    479         paths = self._catalog.uids.items()
    480477        if clear:
    481             paths = tuple(paths)
    482             cat.clear()
     478            self._catalog.clear()
    483479        students = self.portal_catalog(portal_type="Student")
    484480        num_objects = len(students)
     
    518514                                             import_record.Lastname)
    519515                data['matric_no'] = import_record.Entryregno
    520 ##            sub_brains = self.portal_catalog(path = spath)
    521 ##            if len(sub_brains) > 1:
    522 ##                for sub_brain in sub_brains:
    523 ##                    if not sub_brain.portal_type in self.affected_types.keys():
    524 ##                        continue
    525 ##                    doc = sub_brain.getObject().getContent()
    526 ##                    for field in self.affected_types[sub_brain.portal_type]:
    527 ##                        if hasattr(self,'get_from_doc_%s' % field):
    528 ##                            data[field] = getattr(self,'get_from_doc_%s' % field)(doc)
    529 ##                        else:
    530 ##                            data[field] = getattr(doc,field)
    531 ##            elif len(sub_brains) == 1:
    532 ##                #import pdb;pdb.set_trace()
    533 ##                import_res = self.returning_import(id = sid)
    534 ##                if not import_res:
    535 ##                    continue
    536 ##                import_record = import_res[0]
    537 ##                data['matric_no'] = import_record.matric_no
    538 ##                data['sex'] = import_record.Sex == 'F'
    539 ##                data['name'] = "%s %s %s" % (import_record.Firstname,
    540 ##                                             import_record.Middlename,
    541 ##                                             import_record.Lastname)
    542 ##                data['matric_no'] = import_record.Entryregno
    543516            study_course = getattr(student_obj,'study_course',None)
    544517            current_level = data.get('level',None)
     
    571544            data['id'] = object.getId()
    572545            data['review_state'] = self.portal_workflow.getInfoFor(object,'review_state',None)
    573             #from pdb import set_trace;set_trace()
    574546            students_catalog.modifyRecord(**data)
    575547            return
     
    676648    def refreshCatalog(self, clear=0, pghandler=None): ###(
    677649        """ re-index everything we can find """
     650        if clear:
     651            self._catalog.clear()
    678652        courses = self.portal_catalog(portal_type="Course")
    679653        num_objects = len(courses)
    680654        if pghandler:
    681655            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
     656        #from pdb import set_trace;set_trace()
    682657        for i in xrange(num_objects):
    683658            if pghandler: pghandler.report(i)
    684659            course_brain = courses[i]
    685             course_object = course_brain.getObject()
     660            course_doc = course_brain.getObject().getContent()
    686661            pl = course_brain.getPath().split('/')
    687662            data = {}
     663            for field in self.schema():
     664                data[field] = getattr(course_doc,field,None)
    688665            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)
     666            ai = pl.index('academics')
     667            data['faculty'] = pl[ai +1]
     668            data['department'] = pl[ai +2]
     669            if clear:
     670                self.addRecord(**data)
     671            else:
     672                self.modifyRecord(**data)
    693673        if pghandler: pghandler.finish()
    694674    ###)
     
    709689        course_id = object.getId()
    710690        data[self.key] = course_id
    711         if event_type == "sys_add_object":
    712             doc = object.getContent()
    713             #from pdb import set_trace;set_trace()
    714             for field in self.schema():
    715                 if field != self.key:
    716                     data[field] = getattr(doc,field,None)
     691        if event_type == "sys_add_object" and mt == 'CPS Proxy Folder':
    717692            try:
    718693                self.addRecord(**data)
    719694            except ValueError:
    720                 pass
     695                return
     696            course_id = object.getId()
     697            doc = object.getContent()
     698            if doc is None:
     699                return
     700            for field in self.schema():
     701                data[field] = getattr(doc,field,None)
     702            data[self.key] = course_id
     703            ai = rpl.index('academics')
     704            data['faculty'] = rpl[ai +1]
     705            data['department'] = rpl[ai +2]
     706            self.modifyRecord(**data)
     707            return
    721708        if event_type == "sys_del_object":
    722709            self.deleteRecord(course_id)
     710            return
    723711        if event_type == "sys_modify_object" and mt == 'Course':
     712            #from pdb import set_trace;set_trace()
    724713            for field in self.schema():
    725                 if field != self.key:
    726                     data[field] = getattr(object,field,None)
     714                data[field] = getattr(object,field,None)
    727715            course_id = object.aq_parent.getId()
    728716            data[self.key] = course_id
     717            ai = rpl.index('academics')
     718            data['faculty'] = rpl[ai +1]
     719            data['department'] = rpl[ai +2]
    729720            self.modifyRecord(**data)
    730721    ###)
  • WAeUP_SRP/trunk/skins/waeup_academics/getFacultiesInfo.py

    r913 r1724  
    1313"""
    1414request = context.REQUEST
     15def cmp_id(a,b):
     16    s1 = "%(id)s" % a
     17    s2 = "%(id)s" % b
     18    if s1 == s2:
     19        return 0
     20    if s1 > s2:
     21        return 1
     22    return -1
    1523
    1624wf = context.portal_workflow
     
    3240    row['is_editable'] = mtool.checkPermission('Modify portal content', fo)
    3341    items.append(row)
     42items.sort(cmp_id)
    3443info['items'] = items
    3544return info
  • WAeUP_SRP/trunk/skins/waeup_default/id_rename.py

    r681 r1724  
    66Used within the folder_contents template.
    77"""
     8try:
     9    from Products.zdb import set_trace
     10except:
     11    def set_trace():
     12        pass
     13import logging
     14logger = logging.getLogger('Skins.id_rename')
     15mtool = context.portal_membership
     16member = mtool.getAuthenticatedMember()
    817
    918REQUEST = context.REQUEST
     
    1423                                % ('Courses cannot be renamed',)))
    1524
     25old_ids = REQUEST['ids']
    1626new_ids = REQUEST['new_ids']
    1727new_ids = [id.upper() for id in REQUEST['new_ids']]
     
    2030if context.portal_type == "University":
    2131    here = context.academics
    22 
     32pt = context.portal_type
     33mt = context.meta_type
     34logger.info('%s starting renaming %s to %s' % (member,old_ids,new_ids))
    2335
    2436here.manage_renameObjects(REQUEST['ids'], new_ids, REQUEST)
     37if pt == 'University':
     38    for faculty in old_ids:
     39        students = context.students_catalog(faculty=faculty)
     40        student_ids = [s.id for s in students]
     41        data = {}
     42        new_fid = new_ids[old_ids.index(faculty)]
     43        data['faculty'] = new_fid
     44        for sid in student_ids:
     45            data['id'] = sid
     46            context.students_catalog.modifyRecord(**data)
     47        courses = context.courses_catalog(faculty=faculty)
     48        courses_ids = [c.code for c in courses]
     49        for cid in courses_ids:
     50            data['code'] = cid
     51            context.courses_catalogModify(**data)
     52elif pt == 'Faculty':
     53    for department in old_ids:
     54        students = context.students_catalog(department=department)
     55        student_ids = [s.id for s in students]
     56        data = {}
     57        new_did = new_ids[old_ids.index(department)]
     58        data['department'] = new_did
     59        for sid in student_ids:
     60            data['id'] = sid
     61            context.students_catalog.modifyRecord(**data)
     62        courses = context.courses_catalog(department=department)
     63        courses_ids = [c.code for c in courses]
     64        for cid in courses_ids:
     65            data['code'] = cid
     66            context.courses_catalogModify(**data)
     67logger.info('%s finished renaming %s to %s' % (member,old_ids,new_ids))
    2568
    2669return REQUEST.RESPONSE.redirect(here.absolute_url() + \
  • WAeUP_SRP/trunk/skins/waeup_default/id_rename_form.pt

    r586 r1724  
    4646</div><!-- tal:condition="here/folder_rename_items" -->
    4747
    48 <div tal:condition="not: here/folder_rename_items">
     48<div tal:condition="not: here/academics_rename_items">
    4949
    5050  <p i18n:translate="help_no_items_to_rename">
  • WAeUP_SRP/trunk/skins/waeup_default/waeup_document_create_do.py

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

    r1716 r1724  
    102102                                             )
    103103        logger.info('%s edited %s of %s' % (member,context.id,student_id))
    104     elif context.portal_type == "Course": # disable if handled by events
     104    elif context.portal_type == "xxxxCourse": # disabled 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.