Commit cfe41292 authored by Tino Wildenhain's avatar Tino Wildenhain

UnIndex.py now accepts any mapping type for

the extra argument. Its parameter 'indexed_attrs'
can be string with comma delimited attribute names
or list/tuple

This fixes: # 1688
parent 8c9fb0ee
...@@ -16,7 +16,7 @@ $Id$""" ...@@ -16,7 +16,7 @@ $Id$"""
import sys import sys
from cgi import escape from cgi import escape
from logging import getLogger from logging import getLogger
from types import IntType from types import IntType, StringTypes
from BTrees.OOBTree import OOBTree, OOSet from BTrees.OOBTree import OOBTree, OOSet
from BTrees.IOBTree import IOBTree from BTrees.IOBTree import IOBTree
...@@ -65,8 +65,10 @@ class UnIndex(SimpleItem): ...@@ -65,8 +65,10 @@ class UnIndex(SimpleItem):
You will also need to pass in an object in the index and You will also need to pass in an object in the index and
uninded methods for this to work. uninded methods for this to work.
'extra' -- a record-style object that keeps additional 'extra' -- a mapping object that keeps additional
index-related parameters index-related parameters - subitem 'indexed_attrs'
can be string with comma separated attribute names or
a list
'caller' -- reference to the calling object (usually 'caller' -- reference to the calling object (usually
a (Z)Catalog instance a (Z)Catalog instance
...@@ -80,10 +82,12 @@ class UnIndex(SimpleItem): ...@@ -80,10 +82,12 @@ class UnIndex(SimpleItem):
# allow index to index multiple attributes # allow index to index multiple attributes
try: try:
self.indexed_attrs = extra.indexed_attrs.split(',') ia=extra['indexed_attrs']
self.indexed_attrs = [ if type(ia) in StringTypes:
attr.strip() for attr in self.indexed_attrs if attr ] self.indexed_attrs = ia.split(',')
if len(self.indexed_attrs) == 0: self.indexed_attrs = [ self.id ] else:
self.indexed_attrs = list(ia)
self.indexed_attrs = [ attr.strip() for attr in self.indexed_attrs if attr ] or [self.id]
except: except:
self.indexed_attrs = [ self.id ] self.indexed_attrs = [ self.id ]
......
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