Hi,

I have a problem using RestController, ToscaWidgets and Form.encode
all at the same time to edit records (get_one, get_all, new and post
are all working).

So, following the documentation (http://turbogears.org/2.0/docs/main/
RestControllers.html#updating-our-record-in-the-database-with-
validation), I created an edit form with an HiddenField name="_method"
and value="PUT"

This leads to the error: The input field '_method' was not expected.

So following (http://www.mail-archive.com/[email protected]/
msg22893.html) I extended Schema with allow_extra_fields = True.
Putting all together in a @validate decorator as explained in the doc
(http://turbogears.org/2.0/docs/main/Validation.html#schema-
validation) leads to a new error:

>>  @validate(edit_po_form, error_handler=edit, validators=TGSchema())
TypeError: __init__() got multiple values for keyword argument
'validators'

Here is my code:

class PurchaseOrderEditForm(TableForm):

    hover_help = True

    fields = [
        TextField('name', label_text='Order Name', validator=NotEmpty,
            help_text='Please enter the main purpose of this order.'),
        Spacer(),
        ...
        TextArea('description', attrs=dict(rows=3, cols=25),
            help_text='Please provide a short description for this
order.'),
        HiddenField('_method', value="PUT")]

    submit_text = 'Apply changes'

The controller looks like:

    @validate(edit_po_form, error_handler=edit, validators=TGSchema())
    @expose()
    def put(self, id, **kw):
        po = DBSession.query(PurchaseOrder).get(id)
        po.name = kw['name']
        po.order_id = kw['order_id']
        po.purchase_date = kw['purchase_date']
        po.description = kw['description']
        po.supplier_id = kw['supplier_id']
        DBSession.flush()
        flash("The Purchase Order is updated.")
        redirect('/equipment/po/%s' % po.id)

And TGSchema is:

class TGSchema(Schema):
     filter_extra_fields = True
     allow_extra_fields = True

Any comment? I didn't found my error :-(
Best regards
Cédric
--~--~---------~--~----~------------~-------~--~----~
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