>
> Thanks Anthony. I realize that it's not part of the normal API. But I'm 
> working on a plugin to filter one form field based on the value of another 
> (refreshable via ajax). So I'm extending the OptionsWidget class and needed 
> to figure out where that class got its set of options from. I realize this 
> is not a "standard use" scenario, but if we want people to write plugins 
> like this we need to make it easy to get at the internals. It took me 
> another hour or so to figure out how to get the referenced table for a 
> reference field. Enough of my questions on this list seem to be of this 
> kind that I just think it would save your time if it were documented 
> somewhere -- not necessarily in the book, but if it's not somewhere I may 
> make some of my own notes public.


I see your point. Note, documenting "all of the possible properties and 
methods" for a given object or attribute can get tricky, though. For 
example, in this case it is not true that field.requires for a reference 
field always has an options() method (by default it does not). Rather, if 
you create a reference field, and (a) you do not explicitly set the 
"requires" attribute (even to None), (b) the referenced table has a 
"_format" attribute set, and (c) you are defining the field in a call to 
define_table() or Table(), then (d) the reference field will automatically 
be given an IS_IN_DB validator, which happens to have an options() method. 
Otherwise, there will be no options() method (unless you explicitly add the 
IS_IN_DB validator, but in that case it should be simple to assess that the 
validator has an options() method). Part of the difficulty in this case is 
that the field.requires attribute can be any of a number of different 
objects, so it is difficult to comprehensively list all the possible 
methods that those objects might have, particularly when they are assigned 
conditionally. Nevertheless, I agree it would be nice if we could better 
document how some of the magic happens for developers who want to better 
understand the source code.

Anthony

Reply via email to