Glenn Davy <[EMAIL PROTECTED]> writes:

1) Id __like__ to say:
project_formwidget.fields.client.default=p.clientID
However the 500 err tells me that:
AttributeError: 'ProjectFields' object has no attribute 'client', but
clearly it does. How is it that fields.client isn't an attribute?

It isn't.  A widgets.WidgetsList is a common Python list.

The whole implementation of it is here:

================================================================================
class WidgetsList(list):
   """
   A widget list. That's really all. A plain old list that you can
   declare as a classs with widgets ordered as attributes. Syntactic
   sugar for an unsweet world.
   """
   __metaclass__ = MetaWidgetsList

   def __init__(self):
       super(WidgetsList, self).__init__()
       self.extend(self.declared_widgets)
       if len(self) == 0:
           warnings.warn("You have declared an empty WidgetsList")
================================================================================

2) How do I actually designate the 'selected' option?  I passed in
'default=3' in the definition of ProjectFields.client as this is what
seems to be done in most examples I could find, but it doesnt seem to
make a difference.

Turn

client=widgets.SingleSelectField(validator=validators.NotEmpty, \
options=get_client_list_as_options)

into

client=widgets.SingleSelectField(validator=validators.NotEmpty,
       default=3,
       options=get_client_list_as_options)


(You don't need "\" when inside parenthesis...)

It should select option with id 3 (not the third option) if it is available,
otherwise the selected option is browser dependent (some select the lowest ID,
some select the first option on the list -- those might be the same if there's
an option without an id ;-)).

3) By playing in tg-admin shell and importing controllers, I find that I
can use:
project_formwidget.fields[1].default=p.clientID
But it has no effect (as mentioned in 2)), except on one occasion to
give me a 500 error and tell me that changing this wasnt thread safe.

It isn't. You should pass values to your widgets, not change it like that.
So the question is how do I change this, or any other value in the
controller in  a 'thread safe' way?

In your template:

<span py:replace="my_widget(value)" />


In your controller:

  values = dict(
         option = new_value,
         ...
         )
  ...
  return dict(
         ...
         value=values
         ...
         )


There are docs explaining all the process.  I believe that even the 20 minute
wiki shows that...  There are some widgets tutorials available on
docs.turbogears.org as well.  Take some time to read them.

--
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to