Last chunk of portal type classes / zodb property sheets.
[erp5.git] / product / ERP5Form / Document / Preference.py
1 ##############################################################################
2 #
3 # Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
4 # Jerome Perrin <jerome@nexedi.com>
5 #
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
11 # Service Company
12 #
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #
27 ##############################################################################
28
29 from AccessControl import ClassSecurityInfo
30
31 from Products.ERP5Type import Permissions, PropertySheet, Constraint
32 from Products.ERP5Type.Core.Folder import Folder
33 from Products.CMFCore.utils import getToolByName
34 from Products.ERP5Form.PreferenceTool import PreferenceTool
35
36 class Priority:
37 """ names for priorities
38 XXX This was moved to PreferenceTool directly
39 """
40 SITE = 1
41 GROUP = 2
42 USER = 3
43
44 class Preference( Folder ):
45 """
46 A system or user preference
47
48 TODO:
49 - migrate to ERP5Type the whole preference system
50 """
51
52 # CMF Type Definition
53 meta_type = 'ERP5 Preference'
54 portal_type = 'Preference'
55 add_permission = Permissions.AddPortalContent
56
57 # Declarative properties
58 property_sheets = \
59 ( PropertySheet.Base
60 , PropertySheet.XMLObject
61 , PropertySheet.DublinCore
62 , PropertySheet.Preference
63 )
64
65 # Declarative security
66 security = ClassSecurityInfo()
67 security.declareObjectProtected(Permissions.AccessContentsInformation)
68
69 def _clearCache(self):
70 """Clear caches used by methods of this preference
71
72 # TODO: clear different caches according to the preference priority
73 # TODO: (XXX) currently, if one use enables / disables a cache, caches
74 for all other users are reset. This is not good for a system
75 in which users do a lot of preference validation. A better solution
76 is needed for this. But it is not easy because the concept of
77 "per user cache" has been proven to be ambiguous or useless.
78 In theory, a solution could consist in using more keys to
79 select caches or to delete "manually" certain cache keys.
80 """
81 portal_caches = getToolByName(self.getPortalObject(), 'portal_caches')
82 portal_caches.clearCache(cache_factory_list=('erp5_ui_short',))
83
84 def _edit(self, **kw):
85 """edit and clear all caches"""
86 self._clearCache()
87 Folder._edit(self, **kw)
88
89 def enable(self):
90 """Workflow method"""
91 self._clearCache()
92
93 def disable(self):
94 """Workflow method"""
95 self._clearCache()