Commit 3d2761c1 authored by Ayush Tiwari's avatar Ayush Tiwari

CommitTool: Build snapshot after checking if the transition is possible or not

parent fe89ccd1
...@@ -124,17 +124,21 @@ class BusinessCommit(Folder): ...@@ -124,17 +124,21 @@ class BusinessCommit(Folder):
""" """
This function uses the current commit to create a new snapshot This function uses the current commit to create a new snapshot
""" """
portal_commit = self.aq_parent site = self.getPortalObject()
portal_commits = self.aq_parent
# Create empty snapshot # Create empty snapshot
snapshot = portal_commit.newContent(portal_type='Business Snapshot') snapshot = portal_commits.newContent(portal_type='Business Snapshot')
# Add the current commit as predecessor. This way we can have the BI # Add the current commit as predecessor. This way we can have the BI
# BPI in that commit to the Business Snapshot also. # BPI in that commit to the Business Snapshot also.
snapshot.setSimilarValue(self) snapshot.setSimilarValue(self)
self.setSimilarValue(snapshot) self.setSimilarValue(snapshot)
# Build the snapshot # Build the snapshot
snapshot.buildSnapshot() if snapshot not in [None, self]:
if site.portal_workflow.isTransitionPossible(
snapshot, 'build'):
snapshot.build()
return snapshot return snapshot
......
...@@ -150,7 +150,7 @@ class BusinessSnapshot(Folder): ...@@ -150,7 +150,7 @@ class BusinessSnapshot(Folder):
return None return None
def buildSnapshot(self): def build(self, **kwargs):
""" """
Using equivalent commit, create a snapshot of ZODB state Using equivalent commit, create a snapshot of ZODB state
""" """
......
...@@ -179,7 +179,7 @@ class CommitTool (BaseTool): ...@@ -179,7 +179,7 @@ class CommitTool (BaseTool):
return self.objectValues(portal_type='Business Snapshot') return self.objectValues(portal_type='Business Snapshot')
security.declarePublic('newContent') security.declarePublic('newContent')
def newContent(self, id=None, **kw): def newContent(self, id=None, portal_type=None, **kw):
""" """
Override newContent so as to use 'id' generated like hash Override newContent so as to use 'id' generated like hash
Also, create new commit only when all old commits are committed Also, create new commit only when all old commits are committed
...@@ -189,13 +189,13 @@ class CommitTool (BaseTool): ...@@ -189,13 +189,13 @@ class CommitTool (BaseTool):
all_commited = all([l.getTranslatedValidationState() == 'commited' all_commited = all([l.getTranslatedValidationState() == 'commited'
for l in old_commit_list]) for l in old_commit_list])
if not all_commited: if not all_commited and (portal_type == 'Business Commit'):
raise ValueError('Please commit your last commit before creating new one') raise ValueError('Please commit your last commit before creating new one')
if id is None: if id is None:
id = uuid.uuid1() id = uuid.uuid1()
new_obj = super(CommitTool, self).newContent(id, **kw) new_obj = super(CommitTool, self).newContent(id, portal_type,**kw)
# Add the last commit as its predecessor # Add the last commit as its predecessor
commit_list = [l for l commit_list = [l for l
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment