Changeset 1901


Ignore:
Timestamp:
07/24/07 12:47:00 (12 years ago)
Author:
laszlo
Message:

fixed #1468 spent 26h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Resources.py

    r1886 r1901  
    567567            self.storeInHistory(changedFields) 
    568568 
     569    def isID(self, s): 
     570        """ Stupid heuristic to decide s is an id or not. """ 
     571        if len(s) != 32: 
     572            return False 
     573        for i in range(len(s)): 
     574            if s[i] not in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']: 
     575                return False 
     576        return True                 
     577 
     578    def correctReferences(self, oldBodyText, newBodyText): 
     579        """ Delete unused references after restore. """ 
     580        oldIDs = [x for x in oldBodyText if self.isID(x)] 
     581        newIDs = [x for x in newBodyText if self.isID(x)] 
     582        real_newIDs = [x for x in newIDs if x not in oldIDs] 
     583        real_oldIDs = [x for x in oldIDs if x not in newIDs] 
     584        tool = getToolByName(self, 'reference_catalog') 
     585        for x in real_oldIDs: 
     586             tool.deleteReference(self, x, 'uses')     
     587 
    569588    security.declareProtected(MODIFY_CONTENT, 'restoreAVersion') 
    570589    def restoreAVersion(self, timestamp): 
     
    575594                changedFields = [] 
    576595                schema = self.Schema() 
     596                oldBodyText = self.getBodyText() 
    577597                for field in schema.editableFields(self): 
    578598                    if x.has_key(field.getName()): 
     
    580600                        self.getField(field.getName()).set(self, x[field.getName()]) 
    581601                self.storeInHistory(changedFields) 
     602                self.correctReferences(oldBodyText, self.getBodyText())         
    582603        if self.portal_type in MATERIAL_TYPES: 
    583604            return self.REQUEST.RESPONSE.redirect('%s/view' % self.absolute_url()) 
Note: See TracChangeset for help on using the changeset viewer.