[Zope] define a class in a python script
Yuri
yurj at alfa.it
Wed Mar 5 05:45:27 EST 2008
Andreas Jung wrote:
>
>
> --On 5. März 2008 10:21:32 +0100 Yuri <yurj at alfa.it> wrote:
>
>> Hi, all!
>>
>> I would like to define a class inside a python script (so I can catalog
>> it and use catalog to store info, as the tutorial about catalog
>> everything suggests).
>>
>>
>
> This is basically bad-style. Define your class somewhere in your
> product code and if necessary make it available through related APIs
> of the AccessControl module.
>
> -aj
I've found this:
====
If you have a KeywordIndex for the attribute 'foo', then you need to
arrange that the reult objects in your recordset have sequences for the
column / atrribute 'foo'. E.g., for a query like:
select bar.id as 'bar, bar.name as 'name', foo.name as 'foo
from bar, foo where foo.bar_id = bar.id
you need to transform the result set:
bars = {}
for row in rows:
bar_id= row['bar']
bar = bars.get(bar_id)
if bar is None:
bar = bars[bar_id[ = {'bar': bar_id,
'name': row['name'],
'foo': [],
}
bar['foo'].append(row['foo'])
*Now* you can index the records you have transformed:
for bar in bars.values():
catalog.indexObject(compute_uid(bar), make_record(bar))
===
what are compute_uid(bar) and make_record(bar)?
btw, indexes "calls" the object I pass to indexObject or catalog_object,
so I need an object with methods or a dictionary is enough? I'm testing
it, but it is not...
====
def ret_autore(self):
"ritorna un autore"
return 'prova'
un_autore = {}
un_autore['aut']='prova'
#the index is called autore
un_autore.autore = ret_autore
context.catalogo_autori.catalog_object(un_autore, un_autore['aut'])
====
returns:
*Error Type: TypeError*
*Error Value: object has read-only attributes*
More information about the Zope
mailing list