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

Phillip J. Eby pje@telecommunity.com
Thu, 13 Jul 2000 10:40:15 -0500


At 07:11 PM 7/13/00 +0400, Ava wrote:
>
>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.

Try:

data=(self.which_one and [self.second_data] or [first_data])[0]

Then only the correct one will be referenced.

Offhand, I'd guess that there is probably a lot easier way to do what
you're doing, and that you probably don't even need/want "id" to be a
sequence, let alone some of the other things you're doing here.  But
without knowing what your app is actually trying to do, I can't suggest
anything further.