Hey everyone,

I've read everything about TG I can get my hands on but I'm finding
myself stuck with some ugly patterns that I can't simplify and am
wondering if I'm not approaching something the right way.

The most concrete example of this is populating the defaults of
SingleSelectFields.

The way my default dispatcher is set up, it coerces /entity1/id/
entity2/id paths into the relevant entities and labels them as parent
& object accordingly, which it then passes into the controller
actions. So /client/17/contact/3/edit would call
edit(parent=Client.by_id(17), object=Contact.by_id(3)).

Often I'm finding I'm wanting the default options of widgets to be set
based on the values of parent/object. I end up with lots of form
factories that accept the parent/object pair as arguments and
construct the relevant form:

    def edit_form_fields(self, obj=None, parent=None):
        class EditFormFields(WidgetsList):
             role = SingleSelectField(
                label='Role',
                options=parent.role_options(),
                validator=Int(),
                default=1,
                )
        return EditFormFields()

This is called by the edit method on the controller and fed the parent/
object values it received. It just doesn't feel very elegant, as the
controller ends up needing to know a lot about the parent objects. It
also means I'm producing a new form each call.

I'm finding the whole coercing of data into appropriate states
actually pretty confusing. I only just found out about jsonify, but
can't find much in the way of useful information. If I have a single
form that allows for - say - the creation of a client & an associated
contact at the same time, I tend to end up defining properties on the
parent that control the creation of the child. Which means the model
ends up knowing what to expect from the forms, something else I'd
rather avoid. Would it be more appropriate to cooerce the data into an
object via a validator?

Is there any real documentation that covers a full approach to this,
preferably in a holistic way? Something with more than simple fields &
models would be _great_. Trying to piece this together from the docs +
newsgroup posts + random web articles is only making me more confused
in the long run. I have a nice core piece of of working code now but
resolving these issues would help make it cleaner and more extensible.

Thanks!

- alex23


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