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 @@ ...@@ -68,8 +68,7 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from Products.ERP5Type.Cache import clearCache\n <value> <string>from Products.ERP5Type.Message import Message\n
from Products.ERP5Type.Message import Message\n
\n \n
pref = sci.object\n pref = sci.object\n
portal = sci.getPortal()\n portal = sci.getPortal()\n
...@@ -91,8 +90,6 @@ for p in portal.portal_preferences.searchFolder(spec=(\'ERP5 Preference\',)) :\n ...@@ -91,8 +90,6 @@ for p in portal.portal_preferences.searchFolder(spec=(\'ERP5 Preference\',)) :\n
mapping={\'preference_title\': context.getTitle()}) )\n mapping={\'preference_title\': context.getTitle()}) )\n
except \'Unauthorized\', a :\n except \'Unauthorized\', a :\n
LOG("not authorized to deactivate %s"%p)\n LOG("not authorized to deactivate %s"%p)\n
\n
clearCache(method_id="PreferenceTool.CachingMethod.")\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
155 156
\ No newline at end of file \ No newline at end of file
...@@ -30,6 +30,7 @@ from AccessControl import ClassSecurityInfo ...@@ -30,6 +30,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Document.Folder import Folder from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5Type.Cache import clearCache
class Priority: class Priority:
""" names for priorities """ """ names for priorities """
...@@ -63,3 +64,22 @@ class Preference( Folder ): ...@@ -63,3 +64,22 @@ class Preference( Folder ):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) 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): ...@@ -173,14 +173,12 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals( self.assertEquals(
site.getPreferredAccountingTransactionSimulationState(), None) site.getPreferredAccountingTransactionSimulationState(), None)
from Products.ERP5Type.Cache import clearCache
clearCache()
self.assertEquals(len(pref_tool.getPreference( self.assertEquals(len(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')), 0) 'preferred_accounting_transaction_simulation_state_list')), 0)
site.setPreferredAccountingTransactionSimulationStateList( site.edit(
preferred_accounting_transaction_simulation_state_list=
['stopped', 'delivered']) ['stopped', 'delivered'])
clearCache() # FIXME: the cache should be cleared automatically
self.assertEquals(list(pref_tool.getPreference( self.assertEquals(list(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')), 'preferred_accounting_transaction_simulation_state_list')),
list(site.getPreferredAccountingTransactionSimulationStateList())) list(site.getPreferredAccountingTransactionSimulationStateList()))
...@@ -193,22 +191,20 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -193,22 +191,20 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals(pref_tool.getPreference(prop), self.assertEquals(pref_tool.getPreference(prop),
site.getProperty(prop)) site.getProperty(prop))
group.setPreferredAccountingTransactionSimulationStateList(['draft']) group.edit(
clearCache() preferred_accounting_transaction_simulation_state_list=['draft'])
self.assertEquals(list(pref_tool.getPreference( self.assertEquals(list(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')), 'preferred_accounting_transaction_simulation_state_list')),
list(group.getPreferredAccountingTransactionSimulationStateList())) list(group.getPreferredAccountingTransactionSimulationStateList()))
person1.setPreferredAccountingTransactionSimulationStateList( person1.edit(preferred_accounting_transaction_simulation_state_list=
['cancelled']) ['cancelled'])
clearCache()
self.assertEquals(list(pref_tool.getPreference( self.assertEquals(list(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')), 'preferred_accounting_transaction_simulation_state_list')),
list(person1.getPreferredAccountingTransactionSimulationStateList())) list(person1.getPreferredAccountingTransactionSimulationStateList()))
# disable person -> group is selected # disable person -> group is selected
self.getWorkflowTool().doActionFor(person1, self.getWorkflowTool().doActionFor(person1,
'disable_action', wf_id='preference_workflow') 'disable_action', wf_id='preference_workflow')
clearCache()
self.assertEquals(list(pref_tool.getPreference( self.assertEquals(list(pref_tool.getPreference(
'preferred_accounting_transaction_simulation_state_list')), 'preferred_accounting_transaction_simulation_state_list')),
list(group.getPreferredAccountingTransactionSimulationStateList())) 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