[Zope-dev] zpatterns-0.4: defaults attributes, more...

Ava ava@dde974.equipement.gouv.fr
Thu, 13 Jul 2000 19:11:33 +0400


hello,

thanks to philipp for its explanation for 'class_default_for_X'. I'm not at
the office now, and I can't do a reply on the message from the archives ;-)

I have a rack that must retrieve informations from 2 sql tables. I set up 3
generic attribute providers:

- one that get data from the first table, if applicable
- one that get data from the second table, if applicable
- one that merge the two, and take data from either attribute provider
ie:

first generic attribute provider:
    fromexpr = '(self.id[0] and sql_get_first(key=id[0]) or [NOT_FOUND])[0]'
    attrsexprs = ['first_data=RESULT.data']

second generic attribute provider:
    fromexpr = 'self.id[1] and sql_get_first(key=id[1]) or [NOT_FOUND])[1]'
    attrsexprs = ['second_data=RESULT.data']

third generic attribute provider:
    fromexpr = ''
    attrsexprs = [
        'which_one=self.id[1] and 1 or 0',
        'data=[self.first_data, self.second_data][self.which_one]'
        ]

however, this does not work, because if which_one is 0, self.first_data is
ok but self.second_data is taken from NOT_FOUND. An error is raised and all
the attribute served by the third generic attribute provider are ignored.

any ideas to solve that problem??? thanks for any input.
I know, these particular questions are pretty dumb, but I feel like having a
good deal of sleep after finishing this work :-))

regards,
jephte.clain@univ-reunion.fr