Commit c5bb5205 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Fixed dynamic preference generation system.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11814 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 52b3c3b2
...@@ -38,14 +38,29 @@ from Products.ERP5Type.Cache import CachingMethod ...@@ -38,14 +38,29 @@ from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.Accessor.TypeDefinition import list_types from Products.ERP5Type.Accessor.TypeDefinition import list_types
from Products.ERP5Form.Document.Preference import Preference
from Products.ERP5Form import _dtmldir from Products.ERP5Form import _dtmldir
from Products.ERP5Form.Document.Preference import Priority from Products.ERP5Form.Document.Preference import Priority
class func_code: pass class func_code: pass
def createPreferenceMethods(portal) : def updatePreferenceClassPropertySheetList():
# The Preference class should be imported from the common location
# in ERP5Type since it could be overloaded in another product
from Products.ERP5Type.Document.Preference import Preference
# 'Static' property sheets defined on the class
class_property_sheet_list = Preference.property_sheets
# Time to lookup for preferences defined on other modules
property_sheets = list(class_property_sheet_list)
for id in dir(PropertySheet):
if id.endswith('Preference'):
ps = getattr(PropertySheet, id)
if ps not in property_sheets:
property_sheets.append(ps)
class_property_sheet_list = tuple(property_sheets)
Preference.property_sheets = class_property_sheet_list
def createPreferenceToolAccessorList(portal) :
""" """
Initialize all Preference methods on the preference tool. Initialize all Preference methods on the preference tool.
This method must be called on startup. This method must be called on startup.
...@@ -58,7 +73,7 @@ def createPreferenceMethods(portal) : ...@@ -58,7 +73,7 @@ def createPreferenceMethods(portal) :
typestool = getToolByName(portal, 'portal_types') typestool = getToolByName(portal, 'portal_types')
pref_portal_type = typestool.getTypeInfo('Preference') pref_portal_type = typestool.getTypeInfo('Preference')
if pref_portal_type is None: if pref_portal_type is None:
LOG('createPreferenceMethods', PROBLEM, LOG('createPreferenceToolAccessor', PROBLEM,
'Preference type information is not installed.') 'Preference type information is not installed.')
# 'Dynamic' property sheets added through ZMI # 'Dynamic' property sheets added through ZMI
zmi_property_sheet_list = [] zmi_property_sheet_list = []
...@@ -67,19 +82,13 @@ def createPreferenceMethods(portal) : ...@@ -67,19 +82,13 @@ def createPreferenceMethods(portal) :
zmi_property_sheet_list.append( zmi_property_sheet_list.append(
getattr(__import__(property_sheet), property_sheet)) getattr(__import__(property_sheet), property_sheet))
except ImportError, e : except ImportError, e :
LOG('createPreferenceMethods', PROBLEM, LOG('createPreferenceToolAccessor', PROBLEM,
'unable to import Property Sheet %s' % property_sheet, e) 'unable to import Property Sheet %s' % property_sheet, e)
# 'Static' property sheets defined on the class # 'Static' property sheets defined on the class
# The Preference class should be imported from the common location
# in ERP5Type since it could be overloaded in another product
from Products.ERP5Type.Document.Preference import Preference
class_property_sheet_list = Preference.property_sheets class_property_sheet_list = Preference.property_sheets
# Time to lookup for preferences defined on other modules
property_sheets = list(class_property_sheet_list)
for id in dir(PropertySheet):
if id.endswith('Preference'):
ps = getattr(PropertySheet, id)
if ps not in property_sheets:
property_sheets.append(ps)
class_property_sheet_list = tuple(property_sheets)
Preference.property_sheets = class_property_sheet_list
# We can now merge # We can now merge
for property_sheet in ( tuple(zmi_property_sheet_list) + for property_sheet in ( tuple(zmi_property_sheet_list) +
class_property_sheet_list ) : class_property_sheet_list ) :
......
...@@ -466,6 +466,10 @@ class Base( CopyContainer, ...@@ -466,6 +466,10 @@ class Base( CopyContainer,
# Generate portal_type methods # Generate portal_type methods
if not Base.aq_portal_type.has_key(ptype): if not Base.aq_portal_type.has_key(ptype):
if ptype == 'Preference':
# XXX-JPS this should be moved to Preference class
from Products.ERP5Form.PreferenceTool import updatePreferenceClassPropertySheetList
updatePreferenceClassPropertySheetList()
initializePortalTypeDynamicProperties(self, klass, ptype) initializePortalTypeDynamicProperties(self, klass, ptype)
generated = 1 generated = 1
...@@ -502,13 +506,13 @@ class Base( CopyContainer, ...@@ -502,13 +506,13 @@ class Base( CopyContainer,
Base.aq_related_generated = 1 Base.aq_related_generated = 1
# Generate preference methods (since side effect is to reset Preference accessors) # Generate preference methods (since side effect is to reset Preference accessors)
# XXX-JPS - This should be moved to PreferenceTool
if not Base.aq_preference_generated: if not Base.aq_preference_generated:
try : try :
from Products.ERP5Form.PreferenceTool import createPreferenceMethods from Products.ERP5Form.PreferenceTool import createPreferenceToolAccessorList
from Products.ERP5Form.Document.Preference import Preference from Products.ERP5Form.PreferenceTool import updatePreferenceClassPropertySheetList
createPreferenceMethods(self.getPortalObject()) updatePreferenceClassPropertySheetList()
# Force update of Preference accessors createPreferenceToolAccessorList(self.getPortalObject())
initializePortalTypeDynamicProperties(self, Preference, Preference.portal_type)
except ImportError, e : except ImportError, e :
LOG('Base._aq_dynamic', WARNING, LOG('Base._aq_dynamic', WARNING,
'unable to create methods for PreferenceTool', e) 'unable to create methods for PreferenceTool', e)
......
...@@ -149,7 +149,7 @@ class ERP5TypeInformation( FactoryTypeInformation, ...@@ -149,7 +149,7 @@ class ERP5TypeInformation( FactoryTypeInformation,
'delivery_movement', 'discount', 'invoice', 'invoice_movement', 'item', 'delivery_movement', 'discount', 'invoice', 'invoice_movement', 'item',
'order', 'order_movement', 'node', 'payment_node', 'payment_condition', 'order', 'order_movement', 'node', 'payment_node', 'payment_condition',
'resource', 'supply', 'supply_path', 'transformation', 'variation', 'resource', 'supply', 'supply_path', 'transformation', 'variation',
'sub_variation', 'web_document', 'event', 'ticket', 'dms_document', 'sub_variation', 'event', 'ticket', 'document', 'web_document',
'divergence_tester' 'divergence_tester'
) )
group_list = () group_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