コード例 #1
0
 def set_state(self, version_id, state, principal=None):
     """Set state of given version"""
     if str(version_id) not in self:
         return
     # update version state
     version = self[str(version_id)]
     wf_state = IWorkflowState(version)
     wf_state.version_id = version_id
     wf_state.state = state
     if principal is not None:
         wf_state.state_principal = principal
     # update versions/states mapping
     if state is None:
         state = NONE_STATE
     old_state = self.state_by_version[version_id]
     versions = self.versions_by_state[old_state]
     if version_id in versions:
         versions.remove(version_id)
         if versions:
             self.versions_by_state[old_state] = versions
         else:
             del self.versions_by_state[old_state]
     self.state_by_version[version_id] = state
     versions = self.versions_by_state.get(state, [])
     versions.append(version_id)
     self.versions_by_state[state] = versions
コード例 #2
0
 def add_version(self, content, state, principal=None):
     """Add new version to versions list"""
     self.last_version_id += 1
     version_id = self.last_version_id
     # init version state
     alsoProvides(content, IWorkflowVersion)
     wf_state = IWorkflowState(content)
     wf_state.version_id = version_id
     wf_state.state = state
     if principal is not None:
         wf_state.state_principal = principal
     # store new version
     if state is None:
         state = NONE_STATE
     self[str(version_id)] = content
     self.state_by_version[version_id] = state
     versions = self.versions_by_state.get(state, [])
     versions.append(version_id)
     self.versions_by_state[state] = versions
     return version_id