Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
erp5
Commits
b4048cb2
Commit
b4048cb2
authored
Apr 26, 2017
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bt5_config: Use property rather than attributes for BusinessItem objects
parent
7bd395b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
78 deletions
+43
-78
product/ERP5/Document/BusinessManager.py
product/ERP5/Document/BusinessManager.py
+43
-78
No files found.
product/ERP5/Document/BusinessManager.py
View file @
b4048cb2
...
@@ -177,6 +177,7 @@ class BusinessManager(Folder):
...
@@ -177,6 +177,7 @@ class BusinessManager(Folder):
template_path_list
=
()
template_path_list
=
()
template_format_version
=
3
template_format_version
=
3
status
=
'uninstalled'
status
=
'uninstalled'
_path_item_list
=
PersistentList
()
# Declarative security
# Declarative security
security
=
ClassSecurityInfo
()
security
=
ClassSecurityInfo
()
...
@@ -255,7 +256,7 @@ class BusinessManager(Folder):
...
@@ -255,7 +256,7 @@ class BusinessManager(Folder):
final_prop_map
=
prop_map
+
self
.
_properties
final_prop_map
=
prop_map
+
self
.
_properties
return
final_prop_map
return
final_prop_map
def
export
(
self
,
path
=
None
,
local
=
0
,
bma
=
None
,
**
kw
):
def
export
(
self
,
path
=
None
,
**
kw
):
"""
"""
Export the object as zexp file
Export the object as zexp file
"""
"""
...
@@ -336,8 +337,13 @@ class BusinessManager(Folder):
...
@@ -336,8 +337,13 @@ class BusinessManager(Folder):
"""
"""
portal
=
self
.
getPortalObject
()
portal
=
self
.
getPortalObject
()
LOG
(
'Business Manager'
,
INFO
,
'Storing Manager Data'
)
LOG
(
'Business Manager'
,
INFO
,
'Storing Manager Data'
)
self
.
_path_item_list
=
PersistentList
()
path_item_list
=
self
.
getTemplatePathList
()
path_item_list
=
self
.
getTemplatePathList
()
# Delete all the older Business Item objects while rebuilding
exisiting_path_item_id_list
=
[
l
for
l
in
self
.
objectIds
()]
self
.
manage_delObjects
(
ids
=
exisiting_path_item_id_list
)
# Create an empty _path_item_list everytime we storeTemplateData
self
.
_path_item_list
=
PersistentList
()
if
path_item_list
:
if
path_item_list
:
path_item_list
=
[
l
.
split
(
' | '
)
for
l
in
path_item_list
]
path_item_list
=
[
l
.
split
(
' | '
)
for
l
in
path_item_list
]
...
@@ -349,9 +355,9 @@ class BusinessManager(Folder):
...
@@ -349,9 +355,9 @@ class BusinessManager(Folder):
PathItem
=
self
.
newContent
(
portal_type
=
'Business Item'
)
PathItem
=
self
.
newContent
(
portal_type
=
'Business Item'
)
# If its a property, no need to resolve the path
# If its a property, no need to resolve the path
PathItem
.
edit
(
PathItem
.
edit
(
path
=
path_item
[
0
],
item_
path
=
path_item
[
0
],
sign
=
path_item
[
1
],
item_
sign
=
path_item
[
1
],
layer
=
path_item
[
2
]
item_
layer
=
path_item
[
2
]
)
)
self
.
_path_item_list
.
append
(
PathItem
)
self
.
_path_item_list
.
append
(
PathItem
)
else
:
else
:
...
@@ -368,9 +374,9 @@ class BusinessManager(Folder):
...
@@ -368,9 +374,9 @@ class BusinessManager(Folder):
try
:
try
:
PathItem
=
self
.
newContent
(
portal_type
=
'Business Item'
)
PathItem
=
self
.
newContent
(
portal_type
=
'Business Item'
)
PathItem
.
edit
(
PathItem
.
edit
(
path
=
path
,
item_
path
=
path
,
sign
=
path_item
[
1
],
item_
sign
=
path_item
[
1
],
layer
=
path_item
[
2
]
item_
layer
=
path_item
[
2
]
)
)
self
.
_path_item_list
.
append
(
PathItem
)
self
.
_path_item_list
.
append
(
PathItem
)
resolved_path
=
(
' | '
).
join
((
path
,
path_item
[
1
],
path_item
[
2
]))
resolved_path
=
(
' | '
).
join
((
path
,
path_item
[
1
],
path_item
[
2
]))
...
@@ -380,9 +386,9 @@ class BusinessManager(Folder):
...
@@ -380,9 +386,9 @@ class BusinessManager(Folder):
else
:
else
:
PathItem
=
self
.
newContent
(
portal_type
=
'Business Item'
)
PathItem
=
self
.
newContent
(
portal_type
=
'Business Item'
)
PathItem
.
edit
(
PathItem
.
edit
(
path
=
path_item
[
0
],
item_
path
=
path_item
[
0
],
sign
=
path_item
[
1
],
item_
sign
=
path_item
[
1
],
layer
=
path_item
[
2
]
item_
layer
=
path_item
[
2
]
)
)
# If not build, i.e, import/export, just update the _path_item_list
# If not build, i.e, import/export, just update the _path_item_list
self
.
_path_item_list
.
append
(
PathItem
)
self
.
_path_item_list
.
append
(
PathItem
)
...
@@ -651,58 +657,38 @@ class BusinessItem(XMLObject):
...
@@ -651,58 +657,38 @@ class BusinessItem(XMLObject):
isProperty
=
False
isProperty
=
False
isIndexable
=
False
isIndexable
=
False
def
__init__
(
self
,
path
,
sign
=
1
,
layer
=
0
,
value
=
None
,
*
args
,
**
kw
):
def
_edit
(
self
,
item_path
=
''
,
item_sign
=
1
,
item_layer
=
0
,
*
args
,
**
kw
):
"""
Initialize/update the attributes
"""
self
.
__dict__
.
update
(
kw
)
self
.
path
=
path
self
.
sign
=
int
(
sign
)
self
.
layer
=
int
(
layer
)
self
.
value
=
value
if
value
:
# Generate hash of from the value
self
.
sha
=
self
.
_generateHash
()
else
:
self
.
sha
=
''
def
_edit
(
self
,
**
kw
):
"""
"""
Overriden function so that we can update attributes for BusinessItem objects
Overriden function so that we can update attributes for BusinessItem objects
"""
"""
self
.
path
=
kw
.
get
(
'path'
,
''
)
return
super
(
BusinessItem
,
self
).
_edit
(
item_path
=
item_path
,
self
.
sign
=
int
(
kw
.
get
(
'sign'
,
1
))
item_sign
=
item_sign
,
self
.
layer
=
int
(
kw
.
get
(
'layer'
,
0
))
item_layer
=
item_layer
,
self
.
value
=
kw
.
get
(
'value'
,
None
)
**
kw
)
if
self
.
value
:
# Generate hash of from the value
self
.
sha
=
self
.
_generateHash
()
else
:
self
.
sha
=
''
def
_generateHash
(
self
):
def
_generateHash
(
self
,
item_value
=
None
):
"""
"""
Generate hash based on value for the object.
Generate hash based on value for the object.
Initially, for simplicity, we go on with SHA256 values only
Initially, for simplicity, we go on with SHA256 values only
"""
"""
LOG
(
'Business Manager'
,
INFO
,
'Genrating hash'
)
LOG
(
'Business Manager'
,
INFO
,
'Genrating hash'
)
if
not
self
.
value
:
if
not
item_
value
:
# Raise in case there is no value for the BusinessItem object
# Raise in case there is no value for the BusinessItem object
raise
ValueError
,
"Value not defined for the
%s BusinessItem"
%
self
.
path
raise
ValueError
,
"Value not defined for the
BusinessItem"
elif
self
.
isProperty
:
elif
self
.
isProperty
:
# In case of property, the value is a PersisitentMapping object, so it
# In case of property, the value is a PersisitentMapping object, so it
# can be easily hashed after formatting
# can be easily hashed after formatting
sha256
=
hash
(
pprint
.
pformat
(
self
.
value
))
sha256
=
hash
(
pprint
.
pformat
(
item_
value
))
else
:
else
:
# Expects to raise error on case the value for the object
# Expects to raise error on case the value for the object
# is not picklable
# is not picklable
try
:
try
:
sha256
=
hashlib
.
sha256
(
self
.
value
).
hexdigest
()
sha256
=
hashlib
.
sha256
(
item_
value
).
hexdigest
()
except
TypeError
:
except
TypeError
:
obj_dict
=
self
.
value
.
__dict__
.
copy
()
obj_dict
=
item_
value
.
__dict__
.
copy
()
del
obj_dict
[
'uid'
]
del
obj_dict
[
'uid'
]
sha256
=
hash
(
pprint
.
pformat
(
obj_dict
))
sha256
=
hash
(
pprint
.
pformat
(
obj_dict
))
self
.
sha
=
sha256
return
sha256
def
build
(
self
,
context
,
**
kw
):
def
build
(
self
,
context
,
**
kw
):
"""
"""
...
@@ -716,7 +702,7 @@ class BusinessItem(XMLObject):
...
@@ -716,7 +702,7 @@ class BusinessItem(XMLObject):
"""
"""
LOG
(
'Business Manager'
,
INFO
,
'Building Business Item'
)
LOG
(
'Business Manager'
,
INFO
,
'Building Business Item'
)
p
=
context
.
getPortalObject
()
p
=
context
.
getPortalObject
()
path
=
self
.
path
path
=
self
.
getProperty
(
'item_path'
)
if
'#'
in
str
(
path
):
if
'#'
in
str
(
path
):
self
.
isProperty
=
True
self
.
isProperty
=
True
relative_url
,
property_id
=
path
.
split
(
'#'
)
relative_url
,
property_id
=
path
.
split
(
'#'
)
...
@@ -728,11 +714,9 @@ class BusinessItem(XMLObject):
...
@@ -728,11 +714,9 @@ class BusinessItem(XMLObject):
value
[
'name'
]
=
property_id
value
[
'name'
]
=
property_id
value
[
'type'
]
=
property_type
value
[
'type'
]
=
property_type
value
[
'value'
]
=
property_value
value
[
'value'
]
=
property_value
self
.
value
=
value
self
.
setProperty
(
'item_value'
,
value
)
# Add the value object in the database
# Add the value object in the database
obj
.
_p_jar
.
add
(
value
)
obj
.
_p_jar
.
add
(
value
)
# Generate hash for the property value
self
.
_generateHash
()
else
:
else
:
try
:
try
:
# XXX: After we apply _resolve path list while storing Data for the
# XXX: After we apply _resolve path list while storing Data for the
...
@@ -747,9 +731,8 @@ class BusinessItem(XMLObject):
...
@@ -747,9 +731,8 @@ class BusinessItem(XMLObject):
obj
=
obj
.
__of__
(
context
)
obj
=
obj
.
__of__
(
context
)
# XXX: '_recursiveRemoveUid' is not working as expected
# XXX: '_recursiveRemoveUid' is not working as expected
_recursiveRemoveUid
(
obj
)
_recursiveRemoveUid
(
obj
)
self
.
value
=
obj
obj
=
aq_base
(
obj
)
# Generate hash for the erp5 object value
self
.
_setObject
(
obj
.
getId
(),
obj
)
self
.
_generateHash
()
except
AttributeError
:
except
AttributeError
:
# In case the object doesn't exist, just pass without raising error
# In case the object doesn't exist, just pass without raising error
pass
pass
...
@@ -828,18 +811,19 @@ class BusinessItem(XMLObject):
...
@@ -828,18 +811,19 @@ class BusinessItem(XMLObject):
# In case the path denotes property, we create separate object for
# In case the path denotes property, we create separate object for
# ObjectTemplateItem and handle the installation there.
# ObjectTemplateItem and handle the installation there.
portal
=
context
.
getPortalObject
()
portal
=
context
.
getPortalObject
()
if
'#'
in
str
(
self
.
path
):
path
=
self
.
getProperty
(
'item_path'
)
if
'#'
in
str
(
path
):
self
.
isProperty
=
True
self
.
isProperty
=
True
relative_url
,
property_id
=
self
.
path
.
split
(
'#'
)
relative_url
,
property_id
=
path
.
split
(
'#'
)
obj
=
portal
.
unrestrictedTraverse
(
relative_url
)
obj
=
portal
.
unrestrictedTraverse
(
relative_url
)
prop
=
self
.
value
prop
=
self
.
getProperty
(
'value'
)
# First remove the property from the existing path and keep the default
# First remove the property from the existing path and keep the default
# empty, and update only if the sign is +1
# empty, and update only if the sign is +1
obj
.
_delPropValue
(
prop
[
'name'
])
obj
.
_delPropValue
(
prop
[
'name'
])
if
self
.
sign
==
1
:
if
self
.
getProperty
(
'item_sign'
)
==
1
:
obj
.
setProperty
(
prop
[
'name'
],
prop
[
'value'
],
prop
[
'type'
])
obj
.
setProperty
(
prop
[
'name'
],
prop
[
'value'
],
prop
[
'type'
])
else
:
else
:
path_list
=
self
.
path
.
split
(
'/'
)
path_list
=
path
.
split
(
'/'
)
container_path
=
path_list
[:
-
1
]
container_path
=
path_list
[:
-
1
]
object_id
=
path_list
[
-
1
]
object_id
=
path_list
[
-
1
]
try
:
try
:
...
@@ -855,7 +839,7 @@ class BusinessItem(XMLObject):
...
@@ -855,7 +839,7 @@ class BusinessItem(XMLObject):
# 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
self
.
sign
==
1
:
# install object
# install object
obj
=
self
.
value
obj
=
self
.
getProperty
(
'item_value'
)
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
)
...
@@ -1099,32 +1083,13 @@ class BusinessItem(XMLObject):
...
@@ -1099,32 +1083,13 @@ class BusinessItem(XMLObject):
return
obj
return
obj
def
getBusinessPath
(
self
):
def
getBusinessPath
(
self
):
return
self
.
path
return
self
.
getProperty
(
'item_path'
)
def
getBusinessPathSign
(
self
):
def
getBusinessPathSign
(
self
):
return
self
.
sign
return
self
.
getProperty
(
'item_sign'
)
def
getBusinessPathLayer
(
self
):
def
getBusinessPathLayer
(
self
):
return
self
.
layer
return
self
.
getProperty
(
'item_layer'
)
def
getBusinessPathValue
(
self
):
return
self
.
value
def
setBusinessPathValue
(
self
,
value
):
self
.
value
=
value
def
getBusinessPathSha
(
self
):
return
self
.
sha
def
getParentBusinessManager
(
self
):
def
getParentBusinessManager
(
self
):
return
self
.
aq_parent
return
self
.
aq_parent
class
bm
(
dict
):
"""
Fake 'bm' item to read bm/* files through BusinessManagerArchive
"""
def
_importFile
(
self
,
file_name
,
file
,
parent
):
self
[
file_name
]
=
file
.
read
()
#InitializeClass(BusinessItem)
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