Page about CRUD Create Read Update Delete
Crud uses
SQLFORM to generate forms and
SQLTABLE to present data.
See gluon/tools.py, class Crud and
tools/sqlhtml.py, classes SQLFORM and SQLTABLE.
|
From
From: Gary <gary.k.ma...@gmail.com> Thanks.
Like myapp/default/display_manual_form() in the book, right? Two questions. I assume that I need a: def data(): return dict(form=crud()) for each table that uses the crud controller to properly define the URL. If that's true, it's the part that I missed. Second, is it better to call the update directly like: 1) http://hostname/myapp/default/data/update/person/2 or create a controller like: 2) def update1(): redirect(URL(r=request,f='data/update/person/2')) In either case, what should the view be named? Since one might want to have a different view for read,update,delete,etc., it seems that it should be: default/data/update.html, but my testing seems to work at default/ data.html. That seems to imply that using method #2 above with a response.view() would be the better solution. Would you agree with that conclusion or is there a better way to handle this? Thank you. Gary
From: mdipierro <mdipie...@cs.depaul.edu> Date: Mon, 27 Apr 2009 14:48:52 -0700 (PDT) Local: Mon, Apr 27 2009 5:48 pm Subject: Re: Override data/update SQLFORM behavior
On Apr 27, 3:14 pm, Gary <gary.k.ma...@gmail.com> wrote: > Like myapp/default/display_manual_form() in the book, right? > Two questions. I assume that I need a: > def data(): return dict(form=crud()) > for each table that uses the crud controller to properly define the > URL. If that's true, it's the part that I missed.
No. This controller will work for every table in the database. In fact, as you do below, you specify the table in the URL
> 1)http://hostname/myapp/default/data/update/person/2
You create a CRUD action per table
def mycreate(): return dict(form=crud.create(db.mytable))
or an update action
def myupdate(): id=request.args[0] return dict(form=crud.update(db.mytable,id))
> or create a controller like: > 2) def update1(): > redirect(URL(r=request,f='data/update/person/2'))
Do do not do actions that just redirect.
> In either case, what should the view be named?
The view is the controller/action.html
> Since one might want > to have a different view for read,update,delete,etc., it seems that it > should be: > default/data/update.html, but my testing seems to work at default/ > data.html.
you can do
def data(): response.view="%s/%s/%s.html"%(request.controller, request.function, request.args[0]) return dict(form=crud())
From: Gary <gary.k.ma...@gmail.com> Date: Mon, 27 Apr 2009 15:23:28 -0700 (PDT) Local: Mon, Apr 27 2009 6:23 pm Subject: Re: Override data/update SQLFORM behavior
Massimo, Thank you, Thank you, Thank you! This clarified so much and makes a great deal of sense. Kindest regards, Gary
Fom: mdipierro <mdipie...@cs.depaul.edu> Date: Mon, 27 Apr 2009 15:31:17 -0700 (PDT) Local: Mon, Apr 27 2009 6:31 pm Subject: Re: Override data/update SQLFORM behavior
when you call crud you can also specify lots of options...
def mycreate(): return dict(form=crud.create(db.mytable,next=URL(...),onaccept=lambda form:pass,onvalidation=lambda form: pass))
and more. You can also embed them in views
{ {=crud.create(db.mytable)} }
Massimo
From: Gary <gary.k.ma...@gmail.com> Date: Mon, 27 Apr 2009 16:44:28 -0700 (PDT) Local: Mon, Apr 27 2009 7:44 pm Subject: Re: Override data/update SQLFORM behavior
It's going to take some time to digest this, especially the onxxx=lambda part. When would you use the embedded form rather than the controller/view combination above? Are there any examples of the either (or both) the these? If not, once I understand this better, I'd be happy to contribute to the documentation. Thanks again, Gary
From: Álvaro Justen [Turicas] <alvarojus...@gmail.com> Date: Mon, 27 Apr 2009 21:15:08 -0300 Local: Mon, Apr 27 2009 8:15 pm Subject: Re: [web2py:20692] Re: Override data/update SQLFORM behavior
.On Mon, Apr 27, 2009 at 8:44 PM, Gary <gary.k.ma...@gmail.com> wrote: > It's going to take some time to digest this, especially the > onxxx=lambda part. When would you use the embedded form rather than > the controller/view combination above? Are there any examples of the > either (or both) the these? If not, once I understand this better, > I'd be happy to contribute to the documentation.
http://docs.python.org/tutorial/controlflow.html#lambda-forms
Álvaro Justen Peta5 - Telecomunicações e Software Livre 21 3021-6001 / 9898-0141 http://www.peta5.com.br
|
===============================================================================
From http://groups.google.com/group/web2py/browse_thread/thread/f27dfd35fd31265b
From: NewBeen <rui.t...@gmail.com>
Date: Tue, 5 May 2009 08:21:26 -0700 (PDT)
Local: Tues, May 5 2009 11:21 am
Subject: crud problems log events
Greetings I'm trying to log the events when a create a table with crud
but i always get the same error
my code is
in the model
crud.settings.logger=auth
in the controller i try already
@auth.requires_login()
def customcreate():
form = crud.create('databasedp', log='Record %(id)s created')
try to without log and log=crud.settings.create_log
and i always get in the db.auth_event this result
"Record None updated"
but I'm not updating I'm creating a new record some idea what is wrong
From: mdipierro <mdipie...@cs.depaul.edu>
Date: Tue, 5 May 2009 09:16:08 -0700 (PDT)
Local: Tues, May 5 2009 12:16 pm
Subject: Re: crud problems log events
It may be a bug. I will look into it and fix it tonight.
From: NewBeen <rui.t...@gmail.com>
Date: Wed, 6 May 2009 03:31:12 -0700 (PDT)
Local: Wed, May 6 2009 6:31 am
Subject: Re: crud problems log events
Any news about this.... 8-)
Thanks in advance
Rui Gomes
From: mdipierro <mdipie...@cs.depaul.edu>
Date: Wed, 6 May 2009 07:05:49 -0700 (PDT)
Local: Wed, May 6 2009 10:05 am
Subject: Re: crud problems log events
I think I just fixed it in trunk. Please give it a try
=================================================================================