Commit 22bd4b7b authored by Sebastien Robin's avatar Sebastien Robin

updated in order to be able to synchronise cps_schema cps_layout


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@476 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a6e7d641
...@@ -24,34 +24,44 @@ from Products.ERP5Type.Utils import UpperCase ...@@ -24,34 +24,44 @@ from Products.ERP5Type.Utils import UpperCase
from Acquisition import aq_base, aq_inner from Acquisition import aq_base, aq_inner
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.CMFCore.CMFCorePermissions import View from Products.CMFCore.CMFCorePermissions import View
from zLOG import LOG
class PatchedCPSDocument(CPSDocument): class PatchedCPSDocument(CPSDocument):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareProtected( View, '_propertyMap' )
def _propertyMap(self): def _propertyMap(self):
""" """
Returns fake property sheet Returns fake property sheet
""" """
property_sheet = [] property_sheet = []
for schema in self.getTypeInfo().getSchemas(): property_sheet.append(
for field in schema.objectValues(): {
'id' : 'layout_and_schema',
'type' : 'object'
}
)
field_list = self.getTypeInfo().getDataModel(self)._fields.items()
field_list.sort()
for (prop_id,field) in field_list:
#for field in schema.objectValues():
#LOG('testjp',0,'field: %s' % str(field)) #LOG('testjp',0,'field: %s' % str(field))
f_type = None f_type = None
for p in field._properties: #for p in field._properties:
if p['id'] == 'default': # if p['id'] == 'default':
f_type = p['type'] # f_type = p['type']
if isinstance(field,CPSImageField): if isinstance(field,CPSImageField):
f_type = 'object' f_type = 'object'
elif isinstance(field,CPSStringField): elif isinstance(field,CPSStringField):
f_type = 'string' f_type = 'string'
elif isinstance(field,CPSDateTimeField): elif isinstance(field,CPSDateTimeField):
f_type = 'date' f_type = 'string'
elif isinstance(field,CPSFileField): elif isinstance(field,CPSFileField):
f_type = 'object' f_type = 'object'
elif isinstance(field,CPSDocument): elif isinstance(field,CPSDocument):
pass pass
prop_id = schema.getIdUnprefixed(field.id) #prop_id = schema.getIdUnprefixed(field.id)
#if prop_id in ('file_text','content','attachedFile', #if prop_id in ('file_text','content','attachedFile',
# 'attachedFile_html','attachedFile_text', 'content'): # 'attachedFile_html','attachedFile_text', 'content'):
# f_type = 'object' # this should be string, but this strings # f_type = 'object' # this should be string, but this strings
...@@ -75,27 +85,79 @@ class PatchedCPSDocument(CPSDocument): ...@@ -75,27 +85,79 @@ class PatchedCPSDocument(CPSDocument):
Generic accessor. Calls the real accessor Generic accessor. Calls the real accessor
""" """
data_model = self.getTypeInfo().getDataModel(self)
accessor_name = 'get' + UpperCase(key) accessor_name = 'get' + UpperCase(key)
aq_self = aq_base(self) base = aq_base(self)
if key!='content': if data_model.has_key(key):
if hasattr(aq_self, accessor_name): return data_model.get(key)
method = getattr(self, accessor_name) elif hasattr(base,accessor_name):
method = getattr(base,accessor_name)
return method() return method()
prop_type = self.getPropertyType(key) # XXX added by Seb
if prop_type in ('object',):
if hasattr(aq_self, key):
value = getattr(aq_self, key)
value = aq_base(value)
return value
return None return None
elif hasattr(aq_self, key):
value = getattr(aq_self, key) security.declarePrivate('getLayoutAndSchema' )
if callable(value): value = value() def getLayoutAndSchema(self):
return value return (aq_base(self._getOb(".cps_layouts")),aq_base(self._getOb(".cps_schemas")))
security.declarePrivate('setLayoutAndSchema' )
def setLayoutAndSchema(self, data):
"""
data must be : (layout,schema)
"""
self._setOb(".cps_layouts",data[0])
self._setOb(".cps_schemas",data[1])
security.declarePrivate('_setProperty' )
def _setProperty(self, key, value, type='string'):
"""
Set the property for cps objects
"""
LOG('PatchCPSDoc._setProperty',0,'key: %s, value: %s' % (repr(key),repr(value)))
data_model = self.getTypeInfo().getDataModel(self)
#data_model.set(key,value)
type_info = self.getTypeInfo()
kw = {key:value}
type_info.editObject(self,kw)
security.declarePrivate('edit' )
def edit(self, REQUEST=None, force_update = 0, reindex_object = 0, **kw):
return self._edit(REQUEST=REQUEST, force_update=force_update, reindex_object=reindex_object, **kw)
# Object attributes update method
security.declarePrivate( '_edit' )
def _edit(self, REQUEST=None, force_update = 0, reindex_object = 0, **kw):
"""
Generic edit Method for all ERP5 object
The purpose of this method is to update attributed, eventually do
some kind of type checking according to the property sheet and index
the object.
Each time attributes of an object are updated, they should
be updated through this generic edit method
"""
LOG('PatchCPSDoc._edit, kw: ',0,kw)
try:
categoryIds = self._getCategoryTool().getBaseCategoryIds()
except:
categoryIds = []
if kw.has_key('layout_and_schema'):
self.setLayoutAndSchema(kw['layout_and_schema'])
for key in kw.keys():
#if key in categoryIds:
# self._setCategoryMembership(key, kw[key])
if key != 'id' and key!= 'layout_and_schema':
# We only change if the value is different
# This may be very long....
self._setProperty(key, kw[key])
CPSDocument.getProperty = PatchedCPSDocument.getProperty CPSDocument.getProperty = PatchedCPSDocument.getProperty
CPSDocument.getLayoutAndSchema = PatchedCPSDocument.getLayoutAndSchema
CPSDocument.setLayoutAndSchema = PatchedCPSDocument.setLayoutAndSchema
CPSDocument._propertyMap = PatchedCPSDocument._propertyMap CPSDocument._propertyMap = PatchedCPSDocument._propertyMap
CPSDocument.setProperty = Base.setProperty CPSDocument.setProperty = Base.setProperty
CPSDocument._setProperty = Base._setProperty CPSDocument._setProperty = PatchedCPSDocument._setProperty
CPSDocument.asXML = Base.asXML CPSDocument.asXML = Base.asXML
CPSDocument._edit = Base._edit CPSDocument._edit = PatchedCPSDocument._edit
CPSDocument.edit = PatchedCPSDocument._edit
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