vendor/CMF/1.5.2/DCWorkflow

view ContainerTab.py @ 0:e89e53b8c32e

Vendor import of CMF 1.5.2
author fguillaume
date Wed, 20 Jul 2005 16:21:26 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ A convenient base class for representing a container as a management tab.
15 $Id: ContainerTab.py,v 1.6 2004/08/12 15:07:44 jens Exp $
16 """
18 from OFS.Folder import Folder
19 from OFS.SimpleItem import Item_w__name__
20 from Acquisition import aq_base, aq_inner, aq_parent
22 _marker = [] # Create a new marker object.
24 class ContainerTab (Folder):
26 def __init__(self, id):
27 self.id = id
28 self._mapping = {}
30 def getId(self):
31 return self.id
33 def manage_options(self):
34 parent = aq_parent(aq_inner(self))
35 res = []
36 options = parent.manage_options
37 if callable(options):
38 options = options()
39 for item in options:
40 item = item.copy()
41 item['action'] = '../' + item['action']
42 res.append(item)
43 return res
45 def manage_workspace(self, RESPONSE):
46 '''
47 Redirects to the primary option.
48 '''
49 RESPONSE.redirect(self.absolute_url() + '/manage_main')
51 def _checkId(self, id, allow_dup=0):
52 if not allow_dup:
53 if self._mapping.has_key(id):
54 raise 'Bad Request', 'The id "%s" is already in use.' % id
55 return Folder._checkId(self, id, allow_dup)
57 def _getOb(self, name, default=_marker):
58 mapping = self._mapping
59 if mapping.has_key(name):
60 res = mapping[name]
61 if hasattr(res, '__of__'):
62 res = res.__of__(self)
63 return res
64 else:
65 if default is _marker:
66 raise KeyError, name
67 return default
69 def __getattr__(self, name):
70 ob = self._mapping.get(name, None)
71 if ob is not None:
72 return ob
73 raise AttributeError, name
75 def _setOb(self, name, value):
76 mapping = self._mapping
77 mapping[name] = aq_base(value)
78 self._mapping = mapping # Trigger persistence.
80 def _delOb(self, name):
81 mapping = self._mapping
82 del mapping[name]
83 self._mapping = mapping # Trigger persistence.
85 def get(self, name, default=None):
86 if self._mapping.has_key(name):
87 return self[name]
88 else:
89 return default
91 def has_key(self, key):
92 return self._mapping.has_key(key)
94 def objectIds(self, spec=None):
95 # spec is not important for now...
96 return self._mapping.keys()
98 def keys(self):
99 return self._mapping.keys()
101 def items(self):
102 return map(lambda id, self=self: (id, self._getOb(id)),
103 self._mapping.keys())
105 def values(self):
106 return map(lambda id, self=self: self._getOb(id),
107 self._mapping.keys())
109 def manage_renameObjects(self, ids=[], new_ids=[], REQUEST=None):
110 """Rename several sub-objects"""
111 if len(ids) != len(new_ids):
112 raise 'Bad Request', 'Please rename each listed object.'
113 for i in range(len(ids)):
114 if ids[i] != new_ids[i]:
115 self.manage_renameObject(ids[i], new_ids[i])
116 if REQUEST is not None:
117 return self.manage_main(REQUEST)
118 return None