Commit b2d239a7 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Allow to define Portal Types accessor holders and property sheets

created dynamically upon loading of portal type classes, meaningful
for Preference Tool (to get preference values from the default
Preference) and egov (which defines attributes on the portal type
itself)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43886 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent adc18892
...@@ -745,5 +745,26 @@ class PDFTypeInformation(ERP5TypeInformation): ...@@ -745,5 +745,26 @@ class PDFTypeInformation(ERP5TypeInformation):
'mode':'w'}) 'mode':'w'})
ERP5TypeInformation.updatePropertySheetDefinitionDict(self, definition_dict) ERP5TypeInformation.updatePropertySheetDefinitionDict(self, definition_dict)
def getTypePropertySheetValueList(self):
property_sheet_list = super(PDFTypeInformation,
self).getTypePropertySheetValueList()
try:
parsed_scribus_iterator = self._getParsedScribusFile().itervalues()
except AttributeError:
return property_sheet_list
property_sheet = self.getPortalObject().portal_property_sheets.newContent(
id=self.__name__.replace(' ', ''),
portal_type='Property Sheet',
temp_object=True)
for page_content in parsed_scribus_iterator:
for field_name, fields_values in page_content:
property_sheet.newContent(reference=field_name[3:],
elementary_type=fields_values["data_type"],
portal_type='Standard Property',
temp_object=True)
property_sheet_list.append(property_sheet)
return property_sheet_list
...@@ -29,6 +29,61 @@ ...@@ -29,6 +29,61 @@
from Products.ERP5Form.Document.PreferenceType import PreferenceType from Products.ERP5Form.Document.PreferenceType import PreferenceType
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.dynamic.accessor_holder import AccessorHolderType
from Products.ERP5Type.Accessor.TypeDefinition import list_types
from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Form.PreferenceTool import PreferenceMethod
def _generatePreferenceToolAccessorHolder(portal_type_name,
accessor_holder_list):
"""
Generate a specific Accessor Holder that will be put on the Preference Tool.
(This used to happen in ERP5Form.PreferenceTool._aq_dynamic)
We iterate over all properties that do exist on the system, select
the preferences out of those, and generate the getPreferred.*
accessors in erp5.accessor_holder.portal_type.PORTAL_TYPE.PORTAL_TYPE.
"""
import erp5.accessor_holder.portal_type
accessor_holder_module = getattr(erp5.accessor_holder.portal_type,
portal_type_name)
try:
return accessor_holder_module.PreferenceTool
except AttributeError:
# The accessor holder does not already exist
pass
preference_tool_accessor_holder = AccessorHolderType('PreferenceTool')
for accessor_holder in accessor_holder_list:
for prop in accessor_holder._properties:
if not prop.get('preference'):
continue
# XXX read_permission and write_permissions defined at
# property sheet are not respected by this.
# only properties marked as preference are used
# properties have already been 'converted' and _list is appended
# to list_types properties
attribute = prop['id']
if attribute.endswith('_list'):
attribute = prop['base_id']
attr_list = [ 'get%s' % convertToUpperCase(attribute)]
if prop['type'] == 'boolean':
attr_list.append('is%s' % convertToUpperCase(attribute))
if prop['type'] in list_types :
attr_list.append('get%sList' % convertToUpperCase(attribute))
read_permission = prop.get('read_permission')
for attribute_name in attr_list:
method = PreferenceMethod(attribute_name, prop.get('default'))
preference_tool_accessor_holder.registerAccessor(method, read_permission)
accessor_holder_module.registerAccessorHolder(preference_tool_accessor_holder)
return preference_tool_accessor_holder
class PreferenceToolType(PreferenceType): class PreferenceToolType(PreferenceType):
""" """
...@@ -39,3 +94,10 @@ class PreferenceToolType(PreferenceType): ...@@ -39,3 +94,10 @@ class PreferenceToolType(PreferenceType):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
def getAccessorHolderList(self):
accessor_holder_list = super(PreferenceToolType,
self).getAccessorHolderList()
return [_generatePreferenceToolAccessorHolder(self.getPortalType(),
accessor_holder_list)]
...@@ -36,6 +36,8 @@ from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod ...@@ -36,6 +36,8 @@ from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.Utils import deprecated, createExpressionContext from Products.ERP5Type.Utils import deprecated, createExpressionContext
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.dynamic.accessor_holder import getPropertySheetValueList, \
getAccessorHolderList
ERP5TYPE_SECURITY_GROUP_ID_GENERATION_SCRIPT = 'ERP5Type_asSecurityGroupId' ERP5TYPE_SECURITY_GROUP_ID_GENERATION_SCRIPT = 'ERP5Type_asSecurityGroupId'
...@@ -428,6 +430,23 @@ class ERP5TypeInformation(XMLObject, ...@@ -428,6 +430,23 @@ class ERP5TypeInformation(XMLObject,
"""Getter for 'type_base_category' property""" """Getter for 'type_base_category' property"""
return list(self.base_category_list) return list(self.base_category_list)
def getTypePropertySheetValueList(self):
type_property_sheet_list = self.getTypePropertySheetList()
if not type_property_sheet_list:
return []
return getPropertySheetValueList(self.getPortalObject(),
type_property_sheet_list)
def getAccessorHolderList(self):
type_property_sheet_value_list = self.getTypePropertySheetValueList()
if not type_property_sheet_value_list:
return []
return getAccessorHolderList(self.getPortalObject(),
self.getPortalType(),
type_property_sheet_value_list)
# XXX these methods, _baseGetTypeClass, getTypeMixinList, and # XXX these methods, _baseGetTypeClass, getTypeMixinList, and
# getTypeInterfaceList, are required for a bootstrap issue that # getTypeInterfaceList, are required for a bootstrap issue that
# the portal type class Base Type is required for _aq_dynamic on # the portal type class Base Type is required for _aq_dynamic on
...@@ -720,5 +739,4 @@ class ERP5TypeInformation(XMLObject, ...@@ -720,5 +739,4 @@ class ERP5TypeInformation(XMLObject,
setattr(old_action, k, v) setattr(old_action, k, v)
return old_action return old_action
InitializeClass( ERP5TypeInformation ) InitializeClass( ERP5TypeInformation )
...@@ -350,3 +350,71 @@ def applyCategoryAsRelatedValueAccessor(accessor_holder, ...@@ -350,3 +350,71 @@ def applyCategoryAsRelatedValueAccessor(accessor_holder,
for accessor_name in accessor_name_list: for accessor_name in accessor_name_list:
accessor = accessor_class(accessor_name % uppercase_id, id) accessor = accessor_class(accessor_name % uppercase_id, id)
accessor_holder.registerAccessor(accessor, read_permission) accessor_holder.registerAccessor(accessor, read_permission)
def getPropertySheetValueList(site, property_sheet_name_set):
try:
property_sheet_tool = site.portal_property_sheets
except AttributeError:
if not getattr(site, '_v_bootstrapping', False):
LOG("ERP5Type.dynamic", WARNING,
"Property Sheet Tool was not found. Please update erp5_core "
"Business Template")
return []
property_sheet_value_list = []
for property_sheet_name in property_sheet_name_set:
try:
property_sheet = getattr(property_sheet_tool, property_sheet_name)
except AttributeError:
LOG("ERP5Type.dynamic", WARNING,
"Ignoring missing Property Sheet " + property_sheet_name)
continue
else:
property_sheet_value_list.append(property_sheet)
return property_sheet_value_list
expression_context = None
def getAccessorHolderList(site, portal_type_name, property_sheet_value_list):
import erp5.accessor_holder
global expression_context
accessor_holder_list = []
for property_sheet in property_sheet_value_list:
# LOG("ERP5Type.dynamic", INFO,
# "Getting accessor holder for " + property_sheet_name)
property_sheet_name = property_sheet.getId()
if property_sheet.isTempObject():
accessor_holder_module = getattr(erp5.accessor_holder.portal_type,
portal_type_name)
else:
accessor_holder_module = erp5.accessor_holder.property_sheet
try:
accessor_holder_list.append(getattr(accessor_holder_module,
property_sheet_name))
except AttributeError:
# lazily create the context, only if needed.
if expression_context is None:
expression_context = createExpressionContext(site)
# Generate the accessor holder as it has not been done yet
accessor_holder_class = property_sheet.createAccessorHolder(
expression_context, site)
accessor_holder_module.registerAccessorHolder(accessor_holder_class)
accessor_holder_list.append(accessor_holder_class)
# LOG("ERP5Type.dynamic", INFO,
# "Created accessor holder for %s" % property_sheet_name)
return accessor_holder_list
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