Commit 8e57ca29 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Implemented dynamic selection of preference property sheets. It is no longe...

Implemented dynamic selection of preference property sheets. It is no longe necessary to put all propertysheet definitions in ERP5/PropertySheet

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11803 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0c66f8ec
......@@ -39,7 +39,11 @@ class Priority:
USER = 3
class Preference( Folder ):
""" An user preference
"""
A system or user preference
TODO:
- migrate to ERP5Type the whole preference system
"""
# CMF Type Definition
......@@ -50,14 +54,10 @@ class Preference( Folder ):
isRADContent = 1
# Declarative properties
property_sheets = ( PropertySheet.Base
property_sheets = \
( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.DublinCore
, PropertySheet.Preference
, PropertySheet.AccountingPreference
, PropertySheet.SubversionPreference
, PropertySheet.HtmlStylePreference
, PropertySheet.DMSPreference
)
# Declarative security
......
......@@ -33,8 +33,9 @@ from zLOG import LOG, INFO, PROBLEM
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.Base import Base
from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.Accessor.TypeDefinition import list_types
from Products.ERP5Form.Document.Preference import Preference
......@@ -45,8 +46,13 @@ from Products.ERP5Form.Document.Preference import Priority
class func_code: pass
def createPreferenceMethods(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 tool is capable of updating the list of Preference
property sheets by looking at all registered property sheets
and considering those which name ends with 'Preference'
"""
attr_list = []
typestool = getToolByName(portal, 'portal_types')
......@@ -65,6 +71,16 @@ def createPreferenceMethods(portal) :
'unable to import Property Sheet %s' % property_sheet, e)
# '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
# We can now merge
for property_sheet in ( tuple(zmi_property_sheet_list) +
class_property_sheet_list ) :
# then generate common method names
......
......@@ -376,6 +376,7 @@ class Base( CopyContainer,
isIndexable = 1 # If set to 0, reindexing will not happen (useful for optimization)
isPredicate = 0 #
isTemplate = 0 #
isDocument = 0 #
# Dynamic method acquisition system (code generation)
aq_method_generated = {}
......@@ -500,10 +501,14 @@ class Base( CopyContainer,
Base.aq_related_generated = 1
# Generate preference methods (since side effect is to reset Preference accessors)
if not Base.aq_preference_generated:
try :
from Products.ERP5Form.PreferenceTool import createPreferenceMethods
from Products.ERP5Form.Document.Preference import Preference
createPreferenceMethods(self.getPortalObject())
# Force update of Preference accessors
initializePortalTypeDynamicProperties(self, Preference, Preference.portal_type)
except ImportError, e :
LOG('Base._aq_dynamic', WARNING,
'unable to create methods for PreferenceTool', e)
......
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