On Tuesday 17 March 2009 17:34:37 t o b e wrote:
> Rails does this so effortlessly I couldn't believe TG 1.1 doesn't.

That's because TG1.1 should do it without a hitch, at least for SO-objects it 
always did for me.

> To accomplish this I have the following as the base of all my DB model
> objects:
>
> <code>
> # the identity model
>
> class DBObject(object):
>
>   def __init__(self):
>     object.__init__(self)

This is superfluous. Just in case you didn't know :)

>   def get_values(self):
>     values = {}
>     for a in self._sa_class_manager:
>       try:
>         values[a] = self.__getattribute__(a)
>       except:
>         pass
>     return values
> </code>
>
> If you ensure that your form widget fields have the same name as your
> DB columns you can then populate the form quickly with something like:
>
> <code>
>     user = session.query(User).filter(User.user_id == 1).first()
>     form = forms.edit_user.form
>
>     return {
>       "form" : form,
>       "values" : user.get_values()
>     }
> </code>
>
> Have I reinvented the wheel ? Does TG already have this kind of
> thing ?

It should, yes. 

> --
>
> Also: Form Inheritance and field ordering.
>
> If I inherit form B from form A and if form B adds additional fields
> (such as may be hidden from a normal user but visible to an admin
> user) is it possible to affect the ordering of these field when
> displayed ? Current ordering seems to be strictly declaration order.

You can always specify a custom template. Other than that - no, I don't think 
so.

Diez

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