Commit a51d7342 authored by Ayush Tiwari's avatar Ayush Tiwari

bt5_config: Add property to be also considered as BusinessItem objects

parent 388e0bcf
...@@ -53,7 +53,7 @@ from Products.ERP5Type.XMLObject import XMLObject ...@@ -53,7 +53,7 @@ from Products.ERP5Type.XMLObject import XMLObject
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.PythonScripts.PythonScript import PythonScript from Products.PythonScripts.PythonScript import PythonScript
from Products.ERP5Type.dynamic.lazy_class import ERP5BaseBroken from Products.ERP5Type.dynamic.lazy_class import ERP5BaseBroken
from Products.ERP5Type.Globals import Persistent from Products.ERP5Type.Globals import Persistent, PersistentMapping
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from AccessControl import ClassSecurityInfo, Unauthorized, getSecurityManager from AccessControl import ClassSecurityInfo, Unauthorized, getSecurityManager
from Acquisition import Implicit, aq_base, aq_inner, aq_parent from Acquisition import Implicit, aq_base, aq_inner, aq_parent
...@@ -610,6 +610,10 @@ class BusinessItem(Implicit, Persistent): ...@@ -610,6 +610,10 @@ class BusinessItem(Implicit, Persistent):
if not self._value: if not self._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 %s BusinessItem" % self._path
elif self.isProperty:
# In case of property, the value is a PersisitentMapping object, so it
# can be easily hashed after formatting
sha256 = hash(pprint.pformat(self._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
...@@ -619,7 +623,7 @@ class BusinessItem(Implicit, Persistent): ...@@ -619,7 +623,7 @@ class BusinessItem(Implicit, Persistent):
obj_dict = self._value.__dict__.copy() obj_dict = self._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 self._sha = sha256
def build(self, context, **kw): def build(self, context, **kw):
""" """
...@@ -639,7 +643,15 @@ class BusinessItem(Implicit, Persistent): ...@@ -639,7 +643,15 @@ class BusinessItem(Implicit, Persistent):
relative_url, property_id = path.split('#') relative_url, property_id = path.split('#')
obj = p.unrestrictedTraverse(relative_url) obj = p.unrestrictedTraverse(relative_url)
property_value = obj.getProperty(property_id) property_value = obj.getProperty(property_id)
self._value = property_value property_type = obj.getPropertyType(property_id)
# Create a persistent object which can be saved inside ZODB for the value
value = PersistentMapping()
value['name'] = property_id
value['type'] = property_type
value['value'] = property_value
self._value = value
# Add the value object in the database
obj._p_jar.add(value)
# Generate hash for the property value # Generate hash for the property value
self._generateHash() self._generateHash()
else: else:
...@@ -730,10 +742,14 @@ class BusinessItem(Implicit, Persistent): ...@@ -730,10 +742,14 @@ class BusinessItem(Implicit, Persistent):
# 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 self.isProperty: if '#' in str(self._path):
realtive_url, property_id = self._path.split('#') self.isProperty = True
object_property_item = ObjectPropertyTemplateItem(id_list) relative_url, property_id = self._path.split('#')
object_property_item.install() obj = portal.unrestrictedTraverse(relative_url)
# XXX: Here, we do deal with different cases such as if the object exists
# or not or have the same value or compare states
prop = self._value
obj.setProperty(prop['name'], prop['value'], prop['type'])
else: else:
path_list = self._path.split('/') path_list = self._path.split('/')
container_path = path_list[:-1] container_path = path_list[:-1]
...@@ -1004,7 +1020,6 @@ class BusinessItem(Implicit, Persistent): ...@@ -1004,7 +1020,6 @@ class BusinessItem(Implicit, Persistent):
# We now will add the XML object and its sha hash while exporting the object # We now will add the XML object and its sha hash while exporting the object
# to Business Manager itself # to Business Manager itself
# Back compatibility with filesystem Documents # Back compatibility with filesystem Documents
key = self._path key = self._path
obj = self._value obj = self._value
...@@ -1340,5 +1355,3 @@ class bm(dict): ...@@ -1340,5 +1355,3 @@ class bm(dict):
def _importFile(self, file_name, file, parent): def _importFile(self, file_name, file, parent):
self[file_name] = file.read() self[file_name] = file.read()
#InitializeClass(BusinessManager)
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