On Oct 30, 4:44 am, Shane <shane.luttr...@gmail.com> wrote:
> I am using SA within TurboGears.  When saving data from form fields, I
> often have a dict of key/value pairs (where values is always a string
> and must by correctly typed) where each key is set up to correspond to
> a column within the SA Table:
> (Data from fields for a ProductLineItem Type)
> kw = {'bol': u'', 'gross_qty': u'', 'id': u'-1', 'item': u'4',
> 'net_qty': u'', 'order_id': u'2', 'ordered_qty': u'8800', 'supplier':
> u'2', 'terminal': u'8'}

This is Pylons code and not TurboGears, but, they are fairly similar.

from sprox.saormprovider import SAORMProvider
provider=SAORMProvider(meta.Session)

    def account(self):
        client_id = get_client_id()
        tmpl_context.form = contact_form
        tmpl_context.value = meta.Session.query(clients).filter
(clients.client_id==client_id).one()
        return render('/billing_account.mako')

    @validate(contact_form, error_handler='account')
    def accountsave(self):
        kw = request.params.copy()
        kw['client_id'] = get_client_id()
        provider.update(clients, kw)
        h.flash("Account updated")
        redirect_to('/billing/account')

The provider.update(clients, kw)     takes the values from
request.params, sets my primary key (which is not set in the form
schema and is pulled from authkit), and updates the appropriate fields
in the class clients.

In your case, you could probably do:

    def linesave(self, **kw):
        provider.update(line, kw)
        flash("Added Line")
        redirect('/linesaved')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to