Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush Tiwari
erp5
Commits
7bf70402
Commit
7bf70402
authored
Apr 27, 2017
by
Ayush Tiwari
Committed by
Ayush Tiwari
Nov 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bt5_config: Use properties of BM while updating Installation State
parent
716344c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
53 deletions
+50
-53
product/ERP5/Document/BusinessManager.py
product/ERP5/Document/BusinessManager.py
+15
-30
product/ERP5/Tool/TemplateTool.py
product/ERP5/Tool/TemplateTool.py
+35
-23
No files found.
product/ERP5/Document/BusinessManager.py
View file @
7bf70402
...
@@ -153,7 +153,7 @@ class BusinessManager(Folder):
...
@@ -153,7 +153,7 @@ class BusinessManager(Folder):
"""
"""
_properties = (
_properties = (
{'id': '
manager
_path_list',
{'id': '
template
_path_list',
'type': 'lines',
'type': 'lines',
'default': 'python: ()',
'default': 'python: ()',
'acquisition_base_category': (),
'acquisition_base_category': (),
...
@@ -214,26 +214,16 @@ class BusinessManager(Folder):
...
@@ -214,26 +214,16 @@ class BusinessManager(Folder):
portal
=
self
.
getPortalObject
()
portal
=
self
.
getPortalObject
()
pass
pass
def
edit
(
self
,
manager
_path_list
=
[],
**
kw
):
def
edit
(
self
,
template
_path_list
=
[],
**
kw
):
"""
"""
Explicilty edit the class instance
Explicilty edit the class instance
XXX: No need of this class ? as we already have _edit from ERP5Type.Folder
XXX: No need of this class ? as we already have _edit from ERP5Type.Folder
"""
"""
super
(
BusinessManager
,
self
).
edit
(
manager_path_list
=
manager_path_list
,
**
kw
)
super
(
BusinessManager
,
self
).
edit
(
template_path_list
=
template_path_list
,
**
kw
)
def
getTemplatePathList
(
self
):
return
self
.
getProperty
(
'manager_path_list'
)
def
getPathItemList
(
self
):
def
getPathItemList
(
self
):
return
self
.
objectValues
()
return
self
.
objectValues
()
security
.
declareProtected
(
Permissions
.
ManagePortal
,
'_getTemplatePathList'
)
def
_getTemplatePathList
(
self
):
result
=
self
.
getTemplatePathList
()
if
not
isinstance
(
result
,
tuple
):
result
=
tuple
(
result
)
return
result
# XXX: Change into property
# XXX: Change into property
security
.
declareProtected
(
Permissions
.
ManagePortal
,
'getTemplateFormatVersion'
)
security
.
declareProtected
(
Permissions
.
ManagePortal
,
'getTemplateFormatVersion'
)
def
getTemplateFormatVersion
(
self
):
def
getTemplateFormatVersion
(
self
):
...
@@ -289,15 +279,15 @@ class BusinessManager(Folder):
...
@@ -289,15 +279,15 @@ class BusinessManager(Folder):
self
.
title
=
imported_manager
.
title
self
.
title
=
imported_manager
.
title
for
obj
in
imported_manager
.
objectValues
():
for
obj
in
imported_manager
.
objectValues
():
self
.
_setObject
(
obj
.
getId
(),
obj
)
self
.
_setObject
(
obj
.
getId
(),
obj
)
self
.
setProperty
(
'
manager_path_list'
,
obj
.
getTemplatePathList
(
))
self
.
setProperty
(
'
template_path_list'
,
imported_manager
.
getProperty
(
'template_path_list'
))
def
__add__
(
self
,
other
):
def
__add__
(
self
,
other
):
"""
"""
Adds the Business Item objects for the given Business Manager objects
Adds the Business Item objects for the given Business Manager objects
"""
"""
self
.
_path_item_list
.
extend
(
other
.
_path_item_list
)
self
.
_path_item_list
.
extend
(
other
.
_path_item_list
)
manager_path_list
=
list
(
self
.
manager_path_list
)
+
list
(
other
.
manager
_path_list
)
template_path_list
=
list
(
self
.
template_path_list
)
+
list
(
other
.
template
_path_list
)
self
.
manager_path_list
=
manager
_path_list
self
.
template_path_list
=
template
_path_list
return
self
return
self
__radd__
=
__add__
__radd__
=
__add__
...
@@ -330,7 +320,9 @@ class BusinessManager(Folder):
...
@@ -330,7 +320,9 @@ class BusinessManager(Folder):
"""
"""
portal
=
self
.
getPortalObject
()
portal
=
self
.
getPortalObject
()
LOG
(
'Business Manager'
,
INFO
,
'Storing Manager Data'
)
LOG
(
'Business Manager'
,
INFO
,
'Storing Manager Data'
)
path_item_list
=
self
.
getTemplatePathList
()
path_item_list
=
self
.
getProperty
(
'template_path_list'
)
if
not
path_item_list
:
path_item_list
=
()
# Delete all the older Business Item objects while rebuilding
# Delete all the older Business Item objects while rebuilding
exisiting_path_item_id_list
=
[
l
for
l
in
self
.
objectIds
()]
exisiting_path_item_id_list
=
[
l
for
l
in
self
.
objectIds
()]
self
.
manage_delObjects
(
ids
=
exisiting_path_item_id_list
)
self
.
manage_delObjects
(
ids
=
exisiting_path_item_id_list
)
...
@@ -381,7 +373,7 @@ class BusinessManager(Folder):
...
@@ -381,7 +373,7 @@ class BusinessManager(Folder):
if
isBuild
:
if
isBuild
:
# If build process, update the path list of the Business Manager
# If build process, update the path list of the Business Manager
self
.
setProperty
(
'
manager
_path_list'
,
new_path_item_list
)
self
.
setProperty
(
'
template
_path_list'
,
new_path_item_list
)
def
_resolvePath
(
self
,
folder
,
relative_url_list
,
id_list
):
def
_resolvePath
(
self
,
folder
,
relative_url_list
,
id_list
):
"""
"""
...
@@ -417,21 +409,14 @@ class BusinessManager(Folder):
...
@@ -417,21 +409,14 @@ class BusinessManager(Folder):
def
getPathList
(
self
):
def
getPathList
(
self
):
path_list
=
[]
path_list
=
[]
for
item
in
self
.
objectValues
():
for
item
in
self
.
objectValues
():
path_list
.
append
(
item
.
getProperty
(
'path'
))
path_list
.
append
(
item
.
getProperty
(
'
item_
path'
))
return
path_list
return
path_list
def
getPathShaDict
(
self
):
path_sha_dict
=
{}
# TODO: Handle error for BM with multiple items at same path
for
item
in
self
.
objectValues
():
path_sha_dict
[
item
.
getProperty
(
'path'
)]
=
item
.
getProperty
(
'sha'
)
return
path_item_dict
def
getPathItemDict
(
self
):
def
getPathItemDict
(
self
):
path_item_dict
=
{}
path_item_dict
=
{}
# TODO: Handle error for BM with multiple items at same path
# TODO: Handle error for BM with multiple items at same path
for
item
in
self
.
_path_item_list
:
for
item
in
self
.
objectValues
()
:
path_item_dict
[
item
.
path
]
=
item
path_item_dict
[
item
.
getProperty
(
'item_path'
)
]
=
item
return
path_item_dict
return
path_item_dict
def
getBusinessItemByPath
(
self
,
path
):
def
getBusinessItemByPath
(
self
,
path
):
...
@@ -794,9 +779,9 @@ class BusinessItem(XMLObject):
...
@@ -794,9 +779,9 @@ class BusinessItem(XMLObject):
container
.
_delObject
(
object_id
)
container
.
_delObject
(
object_id
)
# Create a new object only if sign is +1
# Create a new object only if sign is +1
# If sign is +1, set the new object on the container
# If sign is +1, set the new object on the container
if
self
.
sign
==
1
:
if
int
(
self
.
getProperty
(
'item_sign'
))
==
1
:
# install object
# install object
obj
=
self
.
getProperty
(
'item_value'
)
obj
=
self
.
objectValues
()[
0
]
obj
=
obj
.
_getCopy
(
container
)
obj
=
obj
.
_getCopy
(
container
)
container
.
_setObject
(
object_id
,
obj
)
container
.
_setObject
(
object_id
,
obj
)
obj
=
container
.
_getOb
(
object_id
)
obj
=
container
.
_getOb
(
object_id
)
...
...
product/ERP5/Tool/TemplateTool.py
View file @
7bf70402
...
@@ -1695,14 +1695,15 @@ class TemplateTool (BaseTool):
...
@@ -1695,14 +1695,15 @@ class TemplateTool (BaseTool):
installed_bm_list
=
self
.
getInstalledBusinessManagerList
()
installed_bm_list
=
self
.
getInstalledBusinessManagerList
()
combined_installed_path_item
=
[
item
for
bm
combined_installed_path_item
=
[
item
for
bm
in
installed_bm_list
in
installed_bm_list
for
item
in
bm
.
_path_item_list
]
for
item
in
bm
.
objectValues
()
]
# Create BM for old installation state and update its path item list
# Create BM for old installation state and update its path item list
old_installation_state
=
self
.
newContent
(
old_installation_state
=
self
.
newContent
(
portal_type
=
'Business Manager'
,
portal_type
=
'Business Manager'
,
title
=
'Old Installation State'
,
title
=
'Old Installation State'
,
)
)
old_installation_state
.
_path_item_list
=
combined_installed_path_item
for
item
in
combined_installed_path_item
:
old_installation_state
.
_setObject
(
item
.
getId
(),
item
)
forbidden_bm_title_list
=
[
'Old Installation State'
,]
forbidden_bm_title_list
=
[
'Old Installation State'
,]
for
bm
in
bm_list
:
for
bm
in
bm_list
:
...
@@ -1715,14 +1716,15 @@ class TemplateTool (BaseTool):
...
@@ -1715,14 +1716,15 @@ class TemplateTool (BaseTool):
combined_new_path_item
=
[
item
for
bm
combined_new_path_item
=
[
item
for
bm
in
new_installed_bm_list
in
new_installed_bm_list
for
item
in
bm
.
_path_item_list
]
for
item
in
bm
.
objectValues
()
]
# Create BM for new installation state and update its path item list
# Create BM for new installation state and update its path item list
new_installation_state
=
self
.
newContent
(
new_installation_state
=
self
.
newContent
(
portal_type
=
'Business Manager'
,
portal_type
=
'Business Manager'
,
title
=
'New Installation State'
,
title
=
'New Installation State'
,
)
)
new_installation_state
.
_path_item_list
=
combined_new_path_item
for
item
in
combined_new_path_item
:
new_installation_state
.
_setObject
(
item
.
getId
(),
item
)
# Create installation process, which have the changes to be made in the
# Create installation process, which have the changes to be made in the
# OFS during installation. Importantly, it should also be a Business Manager
# OFS during installation. Importantly, it should also be a Business Manager
...
@@ -1745,29 +1747,34 @@ class TemplateTool (BaseTool):
...
@@ -1745,29 +1747,34 @@ class TemplateTool (BaseTool):
# Add the removed path with negative sign in the to_install_path_item_list
# Add the removed path with negative sign in the to_install_path_item_list
for
path
in
removed_path_list
:
for
path
in
removed_path_list
:
old_item
=
old_installation_state
.
getBusinessItemByPath
(
path
)
old_item
=
old_installation_state
.
getBusinessItemByPath
(
path
)
old_item
.
s
ign
=
-
1
old_item
.
s
etProperty
(
'item_sign'
,
'-1'
)
to_install_path_item_list
.
append
(
old_item
)
to_install_path_item_list
.
append
(
old_item
)
# XXX: At this point, we expect all the Business Manager objects as 'reduced',
# thus all the BusinessItem sub-objects should have single value
# Update hashes of item in old state before installation
# Update hashes of item in old state before installation
for
item
in
old_installation_state
.
_path_item_list
:
for
item
in
old_installation_state
.
objectValues
()
:
print
item
.
value
value_list
=
item
.
objectValues
()
if
item
.
value
:
if
value_list
:
item
.
s
ha
=
self
.
calculateComparableHash
(
item
.
value
)
item
.
s
etProperty
(
'item_sha'
,
self
.
calculateComparableHash
(
value_list
[
0
])
)
# Path Item List for installation_process should be the difference between
# Path Item List for installation_process should be the difference between
# old and new installation state
# old and new installation state
for
item
in
new_installation_state
.
_path_item_list
:
for
item
in
new_installation_state
.
objectValues
()
:
# If the path has been removed, then add it with sign = -1
# If the path has been removed, then add it with sign = -1
old_item
=
old_installation_state
.
getBusinessItemByPath
(
item
.
path
)
old_item
=
old_installation_state
.
getBusinessItemByPath
(
item
.
getProperty
(
'item_path'
))
# Calculate sha for the items in new_insatallation_state
item
.
setProperty
(
'item_sha'
,
self
.
calculateComparableHash
(
item
.
objectValues
()[
0
]))
if
old_item
:
if
old_item
:
# If the old_item exists, we match the hashes and if it differs, then
# If the old_item exists, we match the hashes and if it differs, then
# add the new item
# add the new item
if
old_item
.
sha
!=
item
.
sha
:
if
old_item
.
getProperty
(
'item_sha'
)
!=
item
.
getProperty
(
'item_sha'
)
:
to_install_path_item_list
.
append
(
item
)
to_install_path_item_list
.
append
(
item
)
else
:
else
:
to_install_path_item_list
.
append
(
item
)
to_install_path_item_list
.
append
(
item
)
installation_process
.
_path_item_list
=
to_install_path_item_list
for
item
in
to_install_path_item_list
:
installation_process
.
_setObject
(
item
.
getId
(),
item
)
error_list
=
self
.
compareOldStateToOFS
(
installation_process
,
old_installation_state
)
error_list
=
self
.
compareOldStateToOFS
(
installation_process
,
old_installation_state
)
...
@@ -1799,8 +1806,12 @@ class TemplateTool (BaseTool):
...
@@ -1799,8 +1806,12 @@ class TemplateTool (BaseTool):
if
attr
.
startswith
(
'_v'
)]
if
attr
.
startswith
(
'_v'
)]
removable_attributes
.
append
(
'uid'
)
removable_attributes
.
append
(
'uid'
)
removable_attributes
.
append
(
'_owner'
)
for
attr
in
removable_attributes
:
for
attr
in
removable_attributes
:
del
obj_dict
[
attr
]
try
:
del
obj_dict
[
attr
]
except
KeyError
:
continue
obj_sha
=
hash
(
pprint
.
pformat
(
obj_dict
))
obj_sha
=
hash
(
pprint
.
pformat
(
obj_dict
))
return
obj_sha
return
obj_sha
...
@@ -1847,13 +1858,13 @@ class TemplateTool (BaseTool):
...
@@ -1847,13 +1858,13 @@ class TemplateTool (BaseTool):
if
old_item
:
if
old_item
:
# Compare hash with ZODB
# Compare hash with ZODB
if
old_item
.
sha
==
obj_sha
:
if
old_item
.
getProperty
(
'item_sha'
)
==
obj_sha
:
# No change at ZODB on old item, so get the new item
# No change at ZODB on old item, so get the new item
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
# Compare new item hash with ZODB
# Compare new item hash with ZODB
if
new_item
.
sha
==
obj_sha
:
if
new_item
.
getProperty
(
'item_sha'
)
==
obj_sha
:
if
new_item
.
sign
==
-
1
:
if
int
(
new_item
.
getProperty
(
'item_sign'
))
==
-
1
:
# If the sign is negative, remove the value from the path
# If the sign is negative, remove the value from the path
new_item
.
install
(
installation_process
)
new_item
.
install
(
installation_process
)
else
:
else
:
...
@@ -1869,7 +1880,7 @@ class TemplateTool (BaseTool):
...
@@ -1869,7 +1880,7 @@ class TemplateTool (BaseTool):
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
# Compare new item hash with ZODB
# Compare new item hash with ZODB
if
new_item
.
sha
==
obj_sha
:
if
new_item
.
getProperty
(
'item_sha'
)
==
obj_sha
:
# If same hash, do nothing
# If same hash, do nothing
continue
continue
...
@@ -1882,7 +1893,7 @@ class TemplateTool (BaseTool):
...
@@ -1882,7 +1893,7 @@ class TemplateTool (BaseTool):
# Compare with the new_item
# Compare with the new_item
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
if
new_item
.
sha
==
obj_sha
:
if
new_item
.
getProperty
(
'item_sha'
)
==
obj_sha
:
# If same hash, do nothing
# If same hash, do nothing
continue
continue
...
@@ -1901,17 +1912,18 @@ class TemplateTool (BaseTool):
...
@@ -1901,17 +1912,18 @@ class TemplateTool (BaseTool):
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
# Check sign of new_item
# Check sign of new_item
if
new_item
.
sign
==
1
:
if
int
(
new_item
.
getProperty
(
'item_sign'
))
==
1
:
error_list
.
append
(
'Object at %s removed by user'
%
path
)
error_list
.
append
(
'Object at %s removed by user'
%
path
)
else
:
else
:
# If there is no item at old state, install the new_item
# If there is no item at old state, install the new_item
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
# XXX: Hack for not trying to install the sub-objects from zexp,
# XXX: Hack for not trying to install the sub-objects from zexp,
# This should rather be implem
neted while exportign
the object,
# This should rather be implem
ented while exporting
the object,
# where we shouldn't export sub-objects in the zexp
# where we shouldn't export sub-objects in the zexp
value
=
new_item
.
value
try
:
if
value
is
None
:
value
=
new_item
.
objectValues
()[
0
]
except
IndexError
:
continue
continue
if
getattr
(
value
,
'_tree'
,
None
):
if
getattr
(
value
,
'_tree'
,
None
):
# This check is required cause only after first access we get the
# This check is required cause only after first access we get the
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment