tg2.1 : How to overwrite a put() method with CrudRestController ?

4 views
Skip to first unread message

khaezzar

unread,
Dec 27, 2009, 12:09:38 PM12/27/09
to TurboGears
Hi,
following : http://beta.turbogears.org/docs//main/Extensions/Crud/index.html
.
I am able to alter the post() but I can't find how to do the same
think with the put() .
Creating a put() method just make the "edit form" redirect me to a bad
request.

do you have an example that works with put() ?

thanks.

###
# my code
# beg
...
# controller
class ContactManagerController(CrudRestController):
model = Contact
table = contact_table
table_filler = contact_table_filler
new_form = contact_add_form
edit_form = contact_edit_form
edit_filler = contact_edit_filler

@expose()
def post(self, **kw):
# do something ...
return super(ContactManagerController, self).post(**kw)

# end
###

Mauro Ciancio

unread,
Dec 27, 2009, 1:14:47 PM12/27/09
to turbo...@googlegroups.com
Hello khaezzar:

On Sun, Dec 27, 2009 at 2:09 PM, khaezzar <kha...@ooeb.com> wrote:
> Creating a put() method just make the "edit form" redirect me to a bad
> request.
> do you have an example that works with put() ?

Yes, It worked for me. Here I leave you an example:

class MyCrudRestController(CrudRestController):
def __init__(self, * args, ** kw):
CrudRestController.__init__(self, * args, ** kw)

@expose('my_edit_template')
def edit(self, * args, ** kw):
return CrudRestController.edit(self, *args, ** kw)

@expose()
@registered_validate(error_handler=edit)
def put(self, * args, ** kw):
# put stuff
return CrudRestController.put(self, * args, ** kw)

Cheers!
--
Mauro Ciancio <maurociancio at gmail dot com>

khaezzar

unread,
Dec 27, 2009, 1:45:01 PM12/27/09
to TurboGears
thanks for your fast answer.
Now it works for me too.
Thanks.

khaezzar

unread,
Dec 27, 2009, 2:20:23 PM12/27/09
to TurboGears
Hi,
following the doc it seems to be better to use the "super" method :

> return CrudRestController.put(self, * args, ** kw)
become
return super(MyCrudRestController, self).put(*args, **kw)

and again: thanks !

On Dec 27, 6:14 pm, Mauro Ciancio <maurocian...@gmail.com> wrote:

khaezzar

unread,
Dec 29, 2009, 1:38:02 PM12/29/09
to TurboGears
Hi,
I just understood that your way seems better as you are sure to call
"put" in the good class.
isn't it ?
Reply all
Reply to author
Forward
0 new messages