コード例 #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 remove_version(self,
                    version_id,
                    state='deleted',
                    comment=None,
                    principal=None,
                    request=None):
     # pylint: disable=too-many-arguments
     """Remove version with given ID"""
     if str(version_id) not in self:
         return
     # update version state
     version = self[str(version_id)]
     wf_state = IWorkflowState(version)
     if comment:
         if request is None:
             request = check_request()
         translate = request.localizer.translate
         workflow = get_utility(
             IWorkflow,
             name=get_parent(self, IWorkflowManagedContent).workflow_name)
         item = WorkflowHistoryItem(
             date=datetime.utcnow(),
             source_version=wf_state.version_id,
             source_state=translate(
                 workflow.states.getTerm(wf_state.state).title),
             target_state=translate(workflow.states.getTerm(state).title),
             principal=request.principal.id,
             comment=comment)
         wf_state.history.append(item)  # pylint: disable=no-member
     wf_state.state = state
     if principal is not None:
         wf_state.state_principal = principal
     # remove given version
     state = self.state_by_version[version_id]
     versions = self.versions_by_state[state]
     versions.remove(version_id)
     if versions:
         self.versions_by_state[state] = versions
     else:
         del self.versions_by_state[state]
     del self.state_by_version[version_id]
     self.deleted[version_id] = self[str(version_id)]
     del self[str(version_id)]
コード例 #3
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