[Zope-CMF] Patch for more forward-compatible APB

Sidnei da Silva sidnei@x3ng.com
Fri, 18 Apr 2003 12:46:32 -0300


--J/dobhs11T7y2rNN
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Howdy folks,

I was testing Plone1_0 with CMF-HEAD after the APB branch merge, and
found a few issues. Of course it isnt required to make it work with
CMF-HEAD, but It seems to me that the changes needed to do it are
harmless.

My patch makes the ActionInformation behave like a dict, which may
benefit also other products that expect actions from the TypesTool to
be a dict. 

In the way, I also added a few __traceback_info__ to make debugging
easier.

[]'s
-- 
Sidnei da Silva (dreamcatcher) <sidnei@x3ng.com.br>
X3ng Web Technology <http://www.x3ng.com.br>
GNU/Linux user 257852
Debian GNU/Linux 3.0 (Sid) 2.4.18 ppc

Less is more or less more
	-- Y_Plentyn on #LinuxGER

--J/dobhs11T7y2rNN
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="apb.patch"

? apb.patch
? CMFCore/refresh.txt
? CMFStaging/refresh.txt
Index: CMFCore/ActionInformation.py
===================================================================
RCS file: /cvs-repository/CMF/CMFCore/ActionInformation.py,v
retrieving revision 1.14
diff -r1.14 ActionInformation.py
26a27,31
> from types import StringType
> 
> _props = ('id', 'title', 'description', 'category', \
>                    'condition', 'permissions', 'priority', \
>                    'visible', 'action')
31c36
<     
---
> 
53c58
<         if condition and type( condition ) == type( '' ):
---
>         if condition and type( condition ) is StringType:
56,57d60
<         if action and type( action ) == type( '' ):
<             action = Expression( action )
62c65
<         self.category = category 
---
>         self.category = category
65c68
<         self.priority = priority 
---
>         self.priority = priority
67c70,133
<         self.action = action
---
>         self.setActionExpression(action)
> 
>     def __len__(self):
>         return len(self.values())
> 
>     def __delitem__(self, key):
>         pass
> 
>     def __getitem__(self, key):
>         if key == 'action':
>             return self.getActionExpression()
>         if key in _props:
>             return self.__dict__[key]
>         raise KeyError, key
> 
>     def __setitem__(self, key, item):
>         if key == 'action':
>             self.setActionExpression(item)
>             return 
>         if key in _props:
>             self.__dict__[key] = item
> 
>     def get(self, key, failobj=None):
>         if key == 'action':
>             return self.getActionExpression()
>         if key in _props:
>             return self.__dict__.get(key, failobj)
>         return failobj
> 
>     def copy(self):
>         return self.clone()
>         
>     def keys(self):
>         result = []
>         for k in _props:
>             if self.__dict__.has_key(k):
>                 result.append(k)
>         return result
> 
>     def items(self):
>         result = []
>         for k in _props:
>             v = self.get(k, None)
>             if v is not None:
>                 result.append((k, v))
>         return result
> 
>     def values(self):
>         result = []
>         for k in _props:
>             v = self.get(k, None)
>             if v is not None:
>                 result.append(v)
>         return result
> 
>     def has_key(self, key):
>         if key in _props and self.__dict__.has_key(k):
>             return 1
>         return 0
> 
>     def update(self, dict):
>         for k, v in dict.items():
>             if k in _props:
>                 self.__setitem__(k, v)
101a168
>         expr = self.getActionExpression()
102a170
>         __traceback_info__ = (info['id'], info['name'], expr)
107c175
<         return info 
---
>         return info
130c198,211
<         return action and action.text or ''
---
>         expr = action and action.text or ''
>         if expr and type( expr ) is StringType:
>             if not expr.startswith('python:')  and not expr.startswith('string:'):
>                 expr = 'string:%s' % expr
>                 self.action = Expression( expr )
>         return expr
> 
>     security.declarePrivate( 'setActionExpression' )
>     def setActionExpression(self, action):
>         if action and type( action ) is StringType:
>             if not action.startswith('python:')  and not action.startswith('string:'):
>                 action = 'string:%s' % action
>             action = Expression( action )
>         self.action = action
Index: CMFCore/ActionProviderBase.py
===================================================================
RCS file: /cvs-repository/CMF/CMFCore/ActionProviderBase.py,v
retrieving revision 1.17
diff -r1.17 ActionProviderBase.py
97,99c97,99
<                  , condition
<                  , permission
<                  , category
---
>                  , condition=''
>                  , permission=()
>                  , category='object'
Index: CMFCore/Expression.py
===================================================================
RCS file: /cvs-repository/CMF/CMFCore/Expression.py,v
retrieving revision 1.5
diff -r1.5 Expression.py
38a39
>         __traceback_info__ = self.text

--J/dobhs11T7y2rNN--