Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
CMFEditions.KeepLastNVersionsTool.KeepLastNVersionsTool Class Reference
Inheritance diagram for CMFEditions.KeepLastNVersionsTool.KeepLastNVersionsTool:
Inheritance graph
[legend]
Collaboration diagram for CMFEditions.KeepLastNVersionsTool.KeepLastNVersionsTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def beforeSaveHook
def retrieveSubstitute

Public Attributes

 maxNumberOfVersionsToKeep

Static Public Attributes

string id = 'portal_purgepolicy'
string alternative_id = 'portal_keeplastnversions'
string meta_type = "CMFEditions Purge Policy Keeping Only the n last Versions"
 manage_options = PropertyManager.manage_options\
int maxNumberOfVersionsToKeep = 1
tuple security = ClassSecurityInfo()

Static Private Attributes

tuple __implements__
tuple _properties

Detailed Description

Definition at line 41 of file KeepLastNVersionsTool.py.


Member Function Documentation

def CMFEditions.KeepLastNVersionsTool.KeepLastNVersionsTool.beforeSaveHook (   self,
  history_id,
  obj,
  metadata = {} 
)
Purge all but the n most current versions

Purges old version so that at maximum ``maxNumberOfVersionsToKeep`` 
versions reside in the history.

Definition at line 71 of file KeepLastNVersionsTool.py.

00071 
00072     def beforeSaveHook(self, history_id, obj, metadata={}):
00073         """Purge all but the n most current versions
00074         
00075         Purges old version so that at maximum ``maxNumberOfVersionsToKeep`` 
00076         versions reside in the history.
00077         """
00078         # check if infinite number of versions shall be stored
00079         if self.maxNumberOfVersionsToKeep == -1:
00080             # infinite: do nothing
00081             return True
00082             
00083         storage = getToolByName(self, 'portal_historiesstorage')
00084         currentVersion = len(storage.getHistory(history_id))
00085         while True:
00086             length = len(storage.getHistory(history_id, countPurged=False))
00087             if length < self.maxNumberOfVersionsToKeep:
00088                 break
00089             comment = "purged on save of version %s" % currentVersion
00090             storage.purge(history_id, 0, metadata={'sys_metadata': {
00091                                                            'comment': comment}
00092                                                    },
00093                           countPurged=False)
00094         
00095         # save current version
00096         return True
    
def CMFEditions.KeepLastNVersionsTool.KeepLastNVersionsTool.retrieveSubstitute (   self,
  history_id,
  selector,
  default = None 
)
Retrives the next older version

If there isn't a next older one returns the next newer one.

Definition at line 97 of file KeepLastNVersionsTool.py.

00097 
00098     def retrieveSubstitute(self, history_id, selector, default=None):
00099         """Retrives the next older version
00100         
00101         If there isn't a next older one returns the next newer one.
00102         """
00103         selector = int(selector)
00104         storage = getToolByName(self, 'portal_historiesstorage')
00105         savedSelector = selector
00106         while selector:
00107             selector -= 1
00108             data = storage.retrieve(history_id, selector, substitute=False)
00109             if data.isValid():
00110                 return data
00111                 
00112         selector = savedSelector
00113         while True:
00114             selector += 1
00115             try:
00116                 data = storage.retrieve(history_id, selector, substitute=False)
00117             except storage.StorageRetrieveError:
00118                 break
00119             
00120             if data.isValid():
00121                 return data
00122                 
00123         return default
00124 
00125 InitializeClass(KeepLastNVersionsTool)

Here is the call graph for this function:


Member Data Documentation

Initial value:
(
        IPurgePolicy,
        SimpleItem.__implements__,
    )

Definition at line 45 of file KeepLastNVersionsTool.py.

Initial value:
(
        {'id': 'maxNumberOfVersionsToKeep', 'type': 'int', 'mode': 'w',
         'label': "maximum number of versions to keep in the storage (set to -1 for infinite)"},
    )

Definition at line 61 of file KeepLastNVersionsTool.py.

string CMFEditions.KeepLastNVersionsTool.KeepLastNVersionsTool.alternative_id = 'portal_keeplastnversions' [static]

Definition at line 52 of file KeepLastNVersionsTool.py.

string CMFEditions.KeepLastNVersionsTool.KeepLastNVersionsTool.id = 'portal_purgepolicy' [static]

Definition at line 51 of file KeepLastNVersionsTool.py.

Definition at line 56 of file KeepLastNVersionsTool.py.

Definition at line 59 of file KeepLastNVersionsTool.py.

Definition at line 78 of file KeepLastNVersionsTool.py.

string CMFEditions.KeepLastNVersionsTool.KeepLastNVersionsTool.meta_type = "CMFEditions Purge Policy Keeping Only the n last Versions" [static]

Definition at line 54 of file KeepLastNVersionsTool.py.

Definition at line 65 of file KeepLastNVersionsTool.py.


The documentation for this class was generated from the following file: