zpatterns-0.4: defaults attributes, more...
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
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.
"Phillip J. Eby" a écrit :
Try: data=(self.which_one and [self.second_data] or [self.first_data])[0]
wow. what a *clever* idea to use [] around self.???_data. I used to write: data=self.which_one and self.second_data or self.first_data but this failed because sometimes self.second_data is a "false" value (eg 0, '', instead of None that I use for empty values), causing self.first_data to be returned instead. one learns about python every day. thanks for the tip. As I wrote in an earlier post, my initial problem was solved using class_defaut_for_X trick
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. I'm writing an application to track issues. I can not just use DC's tracker product, because my customer's needs are very specials. Well, various entities in my application have a so called 'location'. I wish to be able to re-use the application I'm writing, so I abstracted the concept of 'location'. i have then a specialist to manage locations got from a location rack. The rack I wrote for my customer deals with two-headed locations: (site, subdivision). Each part of the location is managed in a different way, but I need the two to identify one's location. Later, when I install that program for a different customer, I want to be able to rip out the old location rack and put another location rack which can be more 'normal' (ie, one-headed) No one will notice except the key to get the location is now an integer (or a string) instead of a tuple.
So, I think I'm doing right to have an id which is a sequence. Thanks for your great help. I'm still fighting to acquire the principle behind zpatterns, but once I get it, I wish I could help others to understand it as well. regards, jephte.clain@univ-reunion.fr
participants (3)
-
Ava -
Jephte CLAIN -
Phillip J. Eby