Changing manage_addLexicon from ZCTextIndex to allow a list of dictionaries to be entered in the elements parameter
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 2 |
Opinion
|
Wishlist
|
Unassigned |
Bug Description
The manage_addLexicon function from the ZCTextIndex module works perfectly when
submiting from the ZMI, where you see entries like:
<input type="hidden" name="elements.
<select name="elements.
...
</select>
If you want to call the manage_addLexicon from python, then you will have to define a
dummy class an assign the required attributes to it. Like this I guess (not tested):
class Dummy
pass
records = []
record = Dummy()
record.group = 'some_group'
record.name = 'some_name'
records.
record = Dummy()
record.group = 'other_group'
record.name = 'other_name'
records.
manage_
I think it would be much cleaner to do this:
records = [{'name'
manage_
So you don't need to define the ugly dummy class. I though it would work, but inside the
manage_addLexicon you use 'hasattr', which doesn't work with a dictionary. Here I just
can thing about two solutions:
1) Inside the manage_addLexicon you could wrapp the 'hasattr', ie: if elements is a list
of dictionaries, then use:
hasattrWrapper = dict.has_key
otherwise use
hasAttrWrapper = hasattr
For the el_record.group and el_record.name calls you could use:
getAttrWrapper = getattr
and for the dictionary:
getAttrWrapper = dict.get
2) The second solution would be to do another method (ie: manage_
which will use from python and where you define the ugly dummy class and assign it the
entered list of dictionaries. Although I preffer the first solution, I think this would
be also an alternative, for the user isn't forced to define such Dummy class him/herself
Regards
Josef
Changed in zope2: | |
importance: | Medium → Wishlist |
Changed in zope2: | |
status: | New → Opinion |
Ok, I rethink the solucion with the dummy class and it would be better:
class Dummy:
def __init__(self, group, name):
self.group = group
self.name = name
records = [] some_group' ,'some_ name') append( record)
record = Dummy('
records.
record = Dummy(' other_group' ,'other_ name') append( record) addLexicon( catalog, 'Lexicon' ,elements= records)
records.
manage_
It looks better than my initial solution. However, I don't see
nice that each zope developer interested in using the manage_addLexicon has to define this class.