Commit d2fdd47c authored by Jérome Perrin's avatar Jérome Perrin

Preference now clear the cache automatically when edited and when the workflow state change.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11126 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a33190c5
......@@ -68,8 +68,7 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.ERP5Type.Cache import clearCache\n
from Products.ERP5Type.Message import Message\n
<value> <string>from Products.ERP5Type.Message import Message\n
\n
pref = sci.object\n
portal = sci.getPortal()\n
......@@ -91,8 +90,6 @@ for p in portal.portal_preferences.searchFolder(spec=(\'ERP5 Preference\',)) :\n
mapping={\'preference_title\': context.getTitle()}) )\n
except \'Unauthorized\', a :\n
LOG("not authorized to deactivate %s"%p)\n
\n
clearCache(method_id="PreferenceTool.CachingMethod.")\n
</string> </value>
</item>
<item>
......
155
\ No newline at end of file
156
\ No newline at end of file
......@@ -30,6 +30,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5Type.Cache import clearCache
class Priority:
""" names for priorities """
......@@ -63,3 +64,22 @@ class Preference( Folder ):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
def _clearCache(self):
"""Clear caches used by methods of this preference
# TODO: clear different caches according to the preference priority
"""
clearCache()
def _edit(self, **kw):
"""edit and clear all caches"""
self._clearCache()
Folder._edit(self, **kw)
def enable(self):
"""Workflow method"""
self._clearCache()
def disable(self):
"""Workflow method"""
self._clearCache()
......@@ -173,14 +173,12 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals(
site.getPreferredAccountingTransactionSimulationState(), None)
from Products.ERP5Type.Cache import clearCache
clearCache()
self.assertEquals(len(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')), 0)
site.setPreferredAccountingTransactionSimulationStateList(
['stopped', 'delivered'])
clearCache() # FIXME: the cache should be cleared automatically
site.edit(
preferred_accounting_transaction_simulation_state_list=
['stopped', 'delivered'])
self.assertEquals(list(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')),
list(site.getPreferredAccountingTransactionSimulationStateList()))
......@@ -193,22 +191,20 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals(pref_tool.getPreference(prop),
site.getProperty(prop))
group.setPreferredAccountingTransactionSimulationStateList(['draft'])
clearCache()
group.edit(
preferred_accounting_transaction_simulation_state_list=['draft'])
self.assertEquals(list(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')),
list(group.getPreferredAccountingTransactionSimulationStateList()))
person1.setPreferredAccountingTransactionSimulationStateList(
person1.edit(preferred_accounting_transaction_simulation_state_list=
['cancelled'])
clearCache()
self.assertEquals(list(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')),
list(person1.getPreferredAccountingTransactionSimulationStateList()))
# disable person -> group is selected
self.getWorkflowTool().doActionFor(person1,
'disable_action', wf_id='preference_workflow')
clearCache()
self.assertEquals(list(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')),
list(group.getPreferredAccountingTransactionSimulationStateList()))
......
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