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,47 +24,57 @@ from Products.ERP5Type.Utils import UpperCase ...@@ -24,47 +24,57 @@ 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(): {
#LOG('testjp',0,'field: %s' % str(field)) 'id' : 'layout_and_schema',
f_type = None 'type' : 'object'
for p in field._properties: }
if p['id'] == 'default': )
f_type = p['type'] field_list = self.getTypeInfo().getDataModel(self)._fields.items()
if isinstance(field,CPSImageField): field_list.sort()
f_type = 'object' for (prop_id,field) in field_list:
elif isinstance(field,CPSStringField): #for field in schema.objectValues():
f_type = 'string' #LOG('testjp',0,'field: %s' % str(field))
elif isinstance(field,CPSDateTimeField): f_type = None
f_type = 'date' #for p in field._properties:
elif isinstance(field,CPSFileField): # if p['id'] == 'default':
f_type = 'object' # f_type = p['type']
elif isinstance(field,CPSDocument): if isinstance(field,CPSImageField):
pass f_type = 'object'
prop_id = schema.getIdUnprefixed(field.id) elif isinstance(field,CPSStringField):
#if prop_id in ('file_text','content','attachedFile', f_type = 'string'
# 'attachedFile_html','attachedFile_text', 'content'): elif isinstance(field,CPSDateTimeField):
# f_type = 'object' # this should be string, but this strings f_type = 'string'
# do so bad xml elif isinstance(field,CPSFileField):
#if not (prop_id in ('file_text','content','attachedFile','attachedFile_html','attachedFile_text')): f_type = 'object'
#if not (prop_id in ('content',)): elif isinstance(field,CPSDocument):
if f_type is not None: pass
property_sheet.append( #prop_id = schema.getIdUnprefixed(field.id)
{ #if prop_id in ('file_text','content','attachedFile',
'id' : prop_id, # 'attachedFile_html','attachedFile_text', 'content'):
'type' : f_type # f_type = 'object' # this should be string, but this strings
} # do so bad xml
) #if not (prop_id in ('file_text','content','attachedFile','attachedFile_html','attachedFile_text')):
#if not (prop_id in ('content',)):
if f_type is not None:
property_sheet.append(
{
'id' : prop_id,
'type' : f_type
}
)
return tuple(property_sheet + list(getattr(self, '_local_properties', ()))) return tuple(property_sheet + list(getattr(self, '_local_properties', ())))
...@@ -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):
return method() method = getattr(base,accessor_name)
prop_type = self.getPropertyType(key) # XXX added by Seb return method()
if prop_type in ('object',): return None
if hasattr(aq_self, key):
value = getattr(aq_self, key) security.declarePrivate('getLayoutAndSchema' )
value = aq_base(value) def getLayoutAndSchema(self):
return value return (aq_base(self._getOb(".cps_layouts")),aq_base(self._getOb(".cps_schemas")))
return None
elif hasattr(aq_self, key): security.declarePrivate('setLayoutAndSchema' )
value = getattr(aq_self, key) def setLayoutAndSchema(self, data):
if callable(value): value = value() """
return value 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