How about defining a creator function for each field, like this:
def field_a_maker():
return TextField()
def field_b_maker():
return TextField()
def field_c_maker():
return TextField()
def field_d_maker():
return TextField()
class FieldListA(WidgetList):
field_a = field_a_maker()
field_b = field_b_maker()
field_c = field_c_maker()
field_d = field_d_maker()
Barry
----- Original Message ----
From: Diez B. Roggisch <[EMAIL PROTECTED]>
To: [email protected]
Sent: Wednesday, January 16, 2008 4:20:43 PM
Subject: [TurboGears] Re: Reduce redundant field declarations
vandevel schrieb:
> I have a few forms that have several fields in common however, the
> order of those fields does differ. In an attempt to avoid redundant
> field declarations, I declared the fields at module level and simply
> referenced the ones that pertained to each field list e.g.:
>
> field_a = TextField()
> field_b = TextField()
> field_c = TextField()
> field_d = TextField()
>
>
> class FieldListA(Widget)
> field_a = field_a
> field_b = field_b
> field_c = field_c
>
> class FieldListB(Widget)
> field_c = field_c
> field_b = field_b
> field_a = field_a
>
> class FieldListC(Widget)
> field_d = field_d
> field_c = field_c
> field_b = field_b
>
>
> This actually worked, but resulted in some funky behaviour such that
> the fields did not display in the declared order when the form was
> rendered. I imagine there must be a sensible way to achieve my goal
> and any advice would be appreciated.
The order is some magic that works through a global counter. I guess
that get's messed up in your somewhat unusal pattern.
You can achieve what you want like this:
field_a = lambda: TextField()
...
Then do
class FieldListB(WidgetsList):
field_a = field_a()
Diez
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search.
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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?hl=en
-~----------~----~----~----~------~----~------~--~---