Jorge Godoy wrote:
> Hi...
>
>
> Continuing to refactor several forms I isolated some common fields and I found
> out that I can "reuse" them inside a new list.  Something like this:
>
> class CommonWidget(widgets.WidgetsList):
>     my_common_widget = widgets.SomeField(...)
>
> class UseCommonWidget(widgets.WidgetsList):
>     one_widget = widgets.OneField(...)
>     another_widget = widgets.AnotherField(...)
>     common = CommonWidget()[0]
>
> class UseCommonWidgetAsWell(widgets.WidgetsList):
>     other_widget = widgets.OtherField(...)
>     yet_another_widget = widgets.YetAnotherField(...)
>     common = CommonWidget()[0]
>     after_common_widget = widgets.AfterCommonField(...)
>
>
>

Actually I would like to strongly discourage nesting WidgetsList in
this way, we end up with some problems related to naming those widgets
and their declarative_counter also I would like to suggest you a far
easier solution that actually works:

from turbogears import widgets

def common_widget():
    return widgets.TextField()

class FooBar(widgets.WidgetsList):
        bar = widgets.TextField()
        common = common_widget()
        foo = widgets.TextField()
        key = common_widget()
        mouse = common_widget()

for widget in FooBar():
    print widget.name

output:

bar
common
foo
key
mouse

Rule of thumb of the day: never nest WidgetsList instances.

This avoids you any sort of problem.

Ciao
Michele


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to