How to use the CRUD functions?

2 views
Skip to first unread message

Gary

unread,
Apr 23, 2009, 5:55:19 PM4/23/09
to web2py Web Framework
This seems so elementary, but it's been bugging me for days. I tried
to find more information in the documentation, in the book, searched
this group and even read the source (as best I could), but I'm
stymied.

When I use the function:

http://localhost:8001/myapp/default/data/update/person/1

the form is displayed as expected, but after the update, the resulting
screen is (redirected to):

http://localhost:8001/myapp/default/data/tables

and I cannot figure out how to change that behavior, for example call
index.

Am I missing something fundamentally simple? Also, what is the best
way to modify the SQLForm that is used in the display. Is there a
better description on how to use the CRUD functions?

Thanks in advance.

Álvaro Justen [Turicas]

unread,
Apr 23, 2009, 6:03:49 PM4/23/09
to web...@googlegroups.com

By default, web2py have in gluon/tools.py, class Crud:
self.settings.create_next = URL(r=request)
self.settings.update_next = URL(r=request)
self.settings.delete_next = URL(r=request)

So, if you have:
mycrud = Crud(globals(), db)
you can change URLs with:

mycrud.settings.create_next = URL(r=request, f='myfunction', args='...')
Same for update_next and delete_next.

--
Álvaro Justen
Peta5 - Telecomunicações e Software Livre
21 3021-6001 / 9898-0141
http://www.peta5.com.br/

Gary

unread,
Apr 23, 2009, 6:17:37 PM4/23/09
to web2py Web Framework
Thank you Alvaro.

Is there a document that details the properties and methods of the
CRUD classes or is it necessary to read the source?

Is there and equally easy fix for replacing the SQLForm used in the
update/add controller function?

Thanks again for the quick response.



On Apr 23, 6:03 pm, Álvaro Justen [Turicas] <alvarojus...@gmail.com>
wrote:

Álvaro Justen [Turicas]

unread,
Apr 23, 2009, 6:28:58 PM4/23/09
to web...@googlegroups.com
On Thu, Apr 23, 2009 at 7:17 PM, Gary <gary.k...@gmail.com> wrote:
> Thank you Alvaro.
>
> Is there a document that details the properties and methods of the
> CRUD classes or is it necessary to read the source?

You can access web2py epydoc:
http://localhost:8000/examples/static/epydoc/index.html
And inside this, you can browse source of funtions/classes.

You also can learn with Auth and Crud examples at:
http://localhost:8000/examples/default/tools

> Is there and equally easy fix for replacing the SQLForm used in the
> update/add controller function?

http://www.web2py.com/AlterEgo/default/show/205

> Thanks again for the quick response.

You're welcome.

Gary

unread,
Apr 24, 2009, 2:27:42 PM4/24/09
to web2py Web Framework
OK. So I've studied a little more and tried some stuff like a custom
form, which loses the ability to enforce restrictions and read the
source code, which is beyond my newbie comprehension and downloaded
Wing IDE to step through the code hoping that it would be easier to
understand what's happening. But, I'm still stumped regarding the the
substitution of a modified SQLFORM. For example, what if I only
wanted to display a subset of fields in the 'read' function.

Looking at the code, it appears that there is no parameter to replace
the 'form' variable and trying to affect it in a similar fashion to
the the 'settings.create_next' (I tried crud.form = SQLFORM(...))
doesn't seem to work (although I could be using the wrong syntax).

Once again, help would be greatly appreciated.

Thanks in advance.


On Apr 23, 6:28 pm, Álvaro Justen [Turicas] <alvarojus...@gmail.com>
wrote:

mdipierro

unread,
Apr 24, 2009, 4:10:13 PM4/24/09
to web2py Web Framework


On Apr 24, 1:27 pm, Gary <gary.k.ma...@gmail.com> wrote:
> OK. So I've studied a little more and tried some stuff like a custom
> form, which loses the ability to enforce restrictions and read the
> source code, which is beyond my newbie comprehension and downloaded
> Wing IDE to step through the code hoping that it would be easier to
> understand what's happening. But, I'm still stumped regarding the the
> substitution of a modified SQLFORM.

I do not understand. who said that ?

Gary

unread,
Apr 24, 2009, 5:19:46 PM4/24/09
to web2py Web Framework
Massimo,

I'm not sure what you are referring to by 'said that'. I'm just
confused. Could you please review the entire thread and see if you
could help?

Thanks so much,
Gary
Reply all
Reply to author
Forward
0 new messages