Commit 9f3e7e53 authored by Jérome Perrin's avatar Jérome Perrin

generate preference tool accessors from preference tool itself


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35108 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 59860df3
......@@ -158,6 +158,8 @@ class PreferenceTool(BaseTool):
allowed_types = ( 'ERP5 Preference',)
security = ClassSecurityInfo()
aq_preference_generated = False
security.declareProtected(
Permissions.ManagePortal, 'manage_overview' )
manage_overview = DTMLFile( 'explainPreferenceTool', _dtmldir )
......@@ -187,6 +189,21 @@ class PreferenceTool(BaseTool):
return method(default)
return default
def _aq_dynamic(self, id):
base_value = PreferenceTool.inheritedAttribute('_aq_dynamic')(self, id)
if not PreferenceTool.aq_preference_generated:
updatePreferenceClassPropertySheetList()
portal = self.getPortalObject()
while portal.portal_type != 'ERP5 Site':
portal = portal.aq_parent.aq_inner.getPortalObject()
createPreferenceToolAccessorList(portal)
PreferenceTool.aq_preference_generated = True
if base_value is None:
return getattr(self, id)
return base_value
security.declareProtected(Permissions.ModifyPortalContent, "setPreference")
def setPreference(self, pref_name, value) :
""" set the preference on the active Preference object"""
......
......@@ -293,7 +293,11 @@ def _aq_reset():
Base.aq_method_generated = {}
Base.aq_portal_type = {}
Base.aq_related_generated = 0
Base.aq_preference_generated = 0
try:
from Products.ERP5Form.PreferenceTool import PreferenceTool
PreferenceTool.aq_preference_generated = False
except ImportError:
LOG('ERP5Type', LOG, "ERP5Form.PreferenceTool not found")
# Some method generations are based on portal methods, and portal methods cache results.
# So it is safer to invalidate the cache.
......@@ -760,9 +764,6 @@ class Base( CopyContainer,
aq_portal_type = {}
aq_related_generated = 0
aq_preference_generated = 0
# FIXME: Preference should not be included in ERP5Type
# Declarative security - in ERP5 we use AccessContentsInformation to
# define the right of accessing content properties as opposed
# to view which is the right to view the object with a form
......@@ -962,20 +963,6 @@ class Base( CopyContainer,
Base.aq_related_generated = 1
# 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:
try :
from Products.ERP5Form.PreferenceTool import createPreferenceToolAccessorList
from Products.ERP5Form.PreferenceTool import updatePreferenceClassPropertySheetList
updatePreferenceClassPropertySheetList()
createPreferenceToolAccessorList(portal)
except ImportError, e :
LOG('Base._aq_dynamic', WARNING,
'unable to create methods for PreferenceTool', e)
raise
Base.aq_preference_generated = 1
# Always try to return something after generation
if generated:
# We suppose that if we reach this point
......
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