Commit 9351d3c4 authored by Nicolas Delaby's avatar Nicolas Delaby

Explain behaviour of constructContent in IConduit, update ERP5Conduit, remove...

Explain behaviour of constructContent in IConduit, update ERP5Conduit, remove useless compatility code with CPS

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16315 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ae020bec
...@@ -128,8 +128,6 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -128,8 +128,6 @@ class ERP5Conduit(XMLSyncUtilsMixin):
[conflict1,conflict2,...] where conclict1 is of the form : [conflict1,conflict2,...] where conclict1 is of the form :
[object.getPath(),keyword,local_and_actual_value,subscriber_value] [object.getPath(),keyword,local_and_actual_value,subscriber_value]
""" """
reset_local_roles = 1
reset_workflow = 1
conflict_list = [] conflict_list = []
xml = self.convertToXml(xml) xml = self.convertToXml(xml)
if xml is None: if xml is None:
...@@ -140,32 +138,32 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -140,32 +138,32 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if self.isHistoryAdd(xml)!=-1: # bad hack XXX to be removed if self.isHistoryAdd(xml)!=-1: # bad hack XXX to be removed
for element in self.getXupdateElementList(xml): for element in self.getXupdateElementList(xml):
xml = self.getElementFromXupdate(element) xml = self.getElementFromXupdate(element)
conflict_list += self.addNode(xml=xml,object=object, conflict_list += self.addNode(
previous_xml=previous_xml, force=force, xml=xml,
simulate=simulate, **kw)['conflict_list'] object=object,
previous_xml=previous_xml,
force=force,
simulate=simulate,
**kw)['conflict_list']
elif xml.nodeName == 'object': elif xml.nodeName == 'object':
if object_id is None: if object_id is None:
object_id = self.getAttribute(xml,'id') object_id = self.getAttribute(xml, 'id')
docid = self.getObjectDocid(xml)
if object_id is not None: if object_id is not None:
if sub_object is None: if sub_object is None:
try: try:
sub_object = object._getOb(object_id) sub_object = object._getOb(object_id)
except (AttributeError, KeyError, TypeError): except (AttributeError, KeyError, TypeError):
sub_object = None sub_object = None
else:
#We prevent reset_workflow an reset_local_roles
reset_local_roles = 0
reset_workflow = 0
if sub_object is None: # If so, it doesn't exist if sub_object is None: # If so, it doesn't exist
portal_type = '' portal_type = ''
if xml.nodeName == 'object': if xml.nodeName == 'object':
portal_type = self.getObjectType(xml) portal_type = self.getObjectType(xml)
elif xml.nodeName in self.XUPDATE_INSERT_OR_ADD: # Deprecated ??? elif xml.nodeName in self.XUPDATE_INSERT_OR_ADD: # Deprecated ???
portal_type = self.getXupdateObjectType(xml) # Deprecated ??? portal_type = self.getXupdateObjectType(xml) # Deprecated ???
sub_object = self.constructContent(object, object_id, docid, sub_object, reset_local_roles, reset_workflow = self.constructContent(
portal_type) object,
reset_local_roles = 0 object_id,
portal_type)
self.newObject( self.newObject(
object=sub_object, object=sub_object,
xml=xml, xml=xml,
...@@ -628,7 +626,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -628,7 +626,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
""" """
xml = self.convertToXml(xml) xml = self.convertToXml(xml)
for subnode in self.getElementNodeList(xml): for subnode in self.getElementNodeList(xml):
if subnode.nodeName==self.xml_object_tag: if subnode.nodeName == self.xml_object_tag:
if object_id == self.getAttribute(subnode,'id'): if object_id == self.getAttribute(subnode,'id'):
return subnode return subnode
return None return None
...@@ -644,17 +642,6 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -644,17 +642,6 @@ class ERP5Conduit(XMLSyncUtilsMixin):
return self.convertXmlValue(data,data_type='string') return self.convertXmlValue(data,data_type='string')
return None return None
security.declareProtected(Permissions.AccessContentsInformation,'getObjectDocid')
def getObjectDocid(self, xml):
"""
Retrieve the docid
"""
for subnode in self.getElementNodeList(xml):
if subnode.nodeName == 'docid':
data = subnode.childNodes[0].value
return self.convertXmlValue(data)
return None
security.declareProtected(Permissions.AccessContentsInformation,'getObjectProperty') security.declareProtected(Permissions.AccessContentsInformation,'getObjectProperty')
def getObjectProperty(self, property, xml, data_type=None): def getObjectProperty(self, property, xml, data_type=None):
""" """
...@@ -830,7 +817,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -830,7 +817,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
#xml_string = xml_string.getvalue() #xml_string = xml_string.getvalue()
#xml_string = unicode(xml_string,encoding='utf-8') #xml_string = unicode(xml_string,encoding='utf-8')
xml_string = self.nodeToString(xml) xml_string = self.nodeToString(xml)
xml_string = unicode(xml_string,encoding='utf-8') xml_string = unicode(xml_string, encoding='utf-8')
#if type(xml_string) is type (u'a'): #if type(xml_string) is type (u'a'):
# xml_string = xml_string.encode('utf-8') # xml_string = xml_string.encode('utf-8')
maxi = max(xml_string.find('>')+1,\ maxi = max(xml_string.find('>')+1,\
...@@ -1014,33 +1001,18 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -1014,33 +1001,18 @@ class ERP5Conduit(XMLSyncUtilsMixin):
return addable return addable
security.declareProtected(Permissions.ModifyPortalContent, 'constructContent') security.declareProtected(Permissions.ModifyPortalContent, 'constructContent')
def constructContent(self, object, object_id, docid, portal_type): def constructContent(self, object, object_id, portal_type):
""" """
This allows to specify how to construct a new content. This allows to specify how to construct a new content.
This is really usefull if you want to write your This is really usefull if you want to write your
own Conduit. own Conduit.
""" """
portal_types = getToolByName(object,'portal_types') portal_types = getToolByName(object, 'portal_types')
#LOG('ERP5Conduit.addNode',0,'portal_type: |%s|' % str(portal_type)) #LOG('ERP5Conduit.addNode',0,'portal_type: |%s|' % str(portal_type))
if docid==None: # ERP5 content
object.newContent(portal_type=portal_type,id=object_id) object.newContent(portal_type=portal_type, id=object_id)
else: # CPS content
# This is specific to CPS, we will call the proxy tool
px_tool= getToolByName(object,'portal_proxies')
trees_tool= getToolByName(object,'portal_trees')
proxy_type = 'document'
if portal_type in ('Workspace','Section'):
proxy_type = 'folder'
proxy = px_tool.createEmptyProxy(proxy_type,
object,portal_type,object_id,docid=docid)
proxy.isIndexable = 0 # So it will not be reindexed, this prevent errors
# Calculate rpath
utool = getToolByName(object, 'portal_url')
rpath = utool.getRelativeUrl(proxy)
px_tool._modifyProxy(proxy,rpath)
trees_tool.notify_tree('sys_modify_object',proxy,rpath)
subobject = object._getOb(object_id) subobject = object._getOb(object_id)
return subobject return subobject, 1, 1
security.declareProtected(Permissions.ModifyPortalContent, 'addWorkflowNode') security.declareProtected(Permissions.ModifyPortalContent, 'addWorkflowNode')
def addWorkflowNode(self, object, xml, simulate): def addWorkflowNode(self, object, xml, simulate):
...@@ -1136,28 +1108,6 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -1136,28 +1108,6 @@ class ERP5Conduit(XMLSyncUtilsMixin):
""" """
return object.getProperty(kw) return object.getProperty(kw)
# This doesn't works fine because all workflows variables
# are not set the same way
# if status.has_key('action'):
# action_name = status['action']
# authorized = 0
# authorized_actions = wf_tool.getActionsFor(object)
# LOG('isWorkflowActionAddable, status:',0,status)
# LOG('isWorkflowActionAddable, authorized_actions:',0,authorized_actions)
# for action in authorized_actions:
# if action['id']==action_name:
# authorized = 1
# if not authorized:
# string_io = StringIO()
# PrettyPrint(xml,stream=string_io)
# conflict = Conflict(object_path=object.getPhysicalPath(),
# keyword=self.history_tag)
# conflict.setXupdate(string_io.getvalue())
# conflict.setRemoteValue(status)
# conflict_list += [conflict]
# return conflict_list
def nodeToString(self, node): def nodeToString(self, node):
""" """
return an xml string corresponding to the node return an xml string corresponding to the node
...@@ -1165,7 +1115,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -1165,7 +1115,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
buf = cStringIO.StringIO() buf = cStringIO.StringIO()
Print(node, stream=buf, encoding='utf-8') Print(node, stream=buf, encoding='utf-8')
xml_string = buf.getvalue() xml_string = buf.getvalue()
buf.close() buf.close()
return xml_string return xml_string
def getGidFromObject(self, object): def getGidFromObject(self, object):
......
...@@ -70,6 +70,21 @@ class IConduit(Interface): ...@@ -70,6 +70,21 @@ class IConduit(Interface):
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""" """
def constructContent(self, object, object_id, portal_type):
"""
This allows to specify how to construct a new content.
This is really usefull if you want to write your
own Conduit.
object: from where new content is created
object_id: id of the new object
portal_type: portal_type of the new object
return newObject, reset_local_roles boolean, reset_workflow boolean
"""
def addNode(self, xml=None, object=None, previous_xml=None, def addNode(self, xml=None, object=None, previous_xml=None,
object_id=None, sub_object=None, force=0, simulate=0, **kw): object_id=None, sub_object=None, force=0, simulate=0, **kw):
""" """
...@@ -113,4 +128,4 @@ class IConduit(Interface): ...@@ -113,4 +128,4 @@ class IConduit(Interface):
def getGidFromXML(self, xml, gid_from_xml_list): def getGidFromXML(self, xml, gid_from_xml_list):
""" """
return the Gid composed with xml informations return the Gid composed with xml informations
""" """
\ No newline at end of file
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