Answers below On May 5, 2:31 am, dlypka <dly...@gmail.com> wrote: > Hi: > > Thank you for this, but I am still not clear on what to code > precisely. > > What exactly needs to be done to satisfy this requiurement: > "Make this template (data.html) the sole template for the crud > controller action" >
If the controller function below is in file controllers\default.py def data(): return dict(form=crud()) then put the suggested contents for its template file in file views\default\data.html > Why does the controller have > def data: return dict(form=crud()) when the variable 'form' would not > be used in the View, since a custom view is to be used instead? > i.e. could we just write > def data: return dict(=crud()) ?? It is up to you as to what you do with the name 'form' in a custom form. The generic template displays it but a custom template does not need to display this name, only to display what it chooses to extract form the object that the name represents. The name is arbitrary but is required for the way the python dict function works. Try it with any name you want, as long as you use a name. For example def data: return dict(testform=crud()) Remember to make sure your template knows what name to expect to extract information with and to avoid messy tests to determine it. > > Where is the code which 'overrides' the auto-generated CRUD form to > point to a custom view? Nothing is overriden with this approach, not even the default template name. If the default template does not exist then the generic template is used. The generic tempate uses the BEAUTIFY helper which has clever tricks that use recursion to traverse information passed. By the time recursion has popped back out again a nice representation has been constructed! > Where is the markup to support the error DIV within the custom view, > to support calls from CRUD to INPUT._validate()? > The crud class does all the messy plumbing for you. For a create form a SQLFORM is used and for the postback a if form.accept test is conducted. If the test passes data is saved ot the database. If the test fails the form is shown again with indications of where validation failed. If validation fails then forms.error is filled in and is used to populate the error DIVs. > Thank you. Your welcome John Heenan > > On May 4, 11:12 am, John Heenan <johnmhee...@gmail.com> wrote: > > > Gary > > > Here is a modifiation of the crud data.html template I have just > > posted. It displays the usual crud forms for everything accept crud > > create forms. > > > It can of course be easily modified to be even more specific for > > specific table create forms. > > > Please give it a try. With this approach you can move gradually move > > towards what you want to do. > > > {{extend 'layout.html'}} > > > {{import re > > m=re.compile('/create/')}} > > {{if not m.search(request.env.path_info):}} > > {{=form}} > > {{else:}} > > <form enctype="multipart/form-data" > > action="{{=request.env.path_info}}" method="post"> > > Make this template (data.html) the sole template for the crud > > controller action<p> > > > def data: return dict(form=crud())<p> > > > Depending on what the crud form action is as determined from parsing > > request.env.path_info use the approach > > in<br>http://mdp.cti.depaul.edu/AlterEgo/default/show/205<br> > > to determine how to layout the crud form<p> > > > <input value="{{=form.formkey}}" type="hidden" name="_formkey" /> > > <input value="{{=form.formname}}" type="hidden" name="_formname" /> > > <input type="submit" name='submit' value="Submit" /> > > </form> > > {{pass}} > > > John Heenan > > > On May 5, 12:19 am, John Heenan <johnmhee...@gmail.com> wrote: > > > > Gary > > > > There is a lot easier way to approach this. > > > > Just keep the crud action as originally designed and intended with > > > def data: > > > return dict(form=crud() > > > > and use a SINGLE template file with a skeleton as indicated below. The > > > particular form action can be found from request.env.path_info. For > > > crud postback it MUST be incorparated back into the form tag. > > > > There is VITAL information > > > inhttp://mdp.cti.depaul.edu/AlterEgo/default/show/205 > > > > Sample single all purpose skeletontemplate for data crud action: > > > > {{extend 'layout.html'}} > > > <form enctype="multipart/form-data" > > > action="{{=request.env.path_info}}" method="post"> > > > > Make this template (data.html) the sole template for the crud > > > controller action<p> > > > > def data: return dict(form=crud())<p> > > > > Depending on what the crud form action is as determined from parsing > > > request.env.path_info use the approach > > > in<br>http://mdp.cti.depaul.edu/AlterEgo/default/show/205<br> > > > to determine how to layout the crud form<p> > > > > <input value="{{=form.formkey}}" type="hidden" name="_formkey" /> > > > <input value="{{=form.formname}}" type="hidden" name="_formname" /> > > > <input type="submit" name='submit' value="Submit" /> > > > </form> > > > > Regards > > > > John Heenan > > > > On May 4, 12:46 pm, Gary <gary.k.ma...@gmail.com> wrote: > > > > > To see where I'm going with this, I've modified the controller to use > > > > the base read/create/update controller (setsubmit) so it can be used > > > > with a minimum of new code. Here is the new version adding a > > > > controller 'authdata' for the auth_user table: > > > > > def index(): > > > > session.action = "update" > > > > # redirect(URL(r=request,f='testdata')) > > > > redirect(URL(r=request,f='authdata')) > > > > > @auth.requires_login() > > > > def testdata(): > > > > if request.args: id = request.args[0] > > > > else: id = 3 # Included for testing > > > > x = eval(setsubmit("testtable")) > > > > return dict(form=x) > > > > > @auth.requires_login() > > > > def authdata(): > > > > if request.args: id = request.args[0] > > > > else: id = 1 # Included for testing > > > > x = eval(setsubmit("auth_user")) > > > > return dict(form=x) > > > > > def setsubmit(table): > > > > if request.vars.submit1: session.action = "create" > > > > if request.vars.submit2: session.action = "update" > > > > if request.vars.submit3 or request.vars.submit4: session.action = > > > > "read" > > > > cmd = "crud."+session.action+"(db."+table > > > > if session.action in ['read','update']: > > > > cmd += ",id)" > > > > else: > > > > cmd += ")" > > > > return cmd > > > > > def data(): > > > > response.view="%s/%s/%s.html" % > > > > (request.controller,request.function, request.args[0]) > > > > return dict(form=crud()) > > > > > def user(): > > > > return dict(form=auth()) > > > > > Although I'm sure this can be improved (maybe by using response.form > > > > and passing the table name), by adding a just the controller > > > > 'authdata' and creating a 'default/authdata.html custom view, the > > > > logic works for the new custom form with a minimum of effort. I > > > > believe that a small program could be written to create a skeleton of > > > > the view that would take most of the work out of the process. I saw > > > > on AlterEgo athttp://mdp.cti.depaul.edu/AlterEgo/default/show/82that > > > > Massimo built a small application to create this functionality from > > > > SQL. I hope that this will be helpful to the project. > > > > > Regards, > > > > Gary > > > > > PS. Here's the view (default/authdata.html) for the above: > > > > > {{extend 'layout.html'}} > > > > <h1>Auth_data > > > > {{if session.action == "update":}} > > > > Update > > > > {{elif session.action == "create":}} > > > > Add > > > > {{pass}} > > > > </h1> > > > > <form action="" enctype="multipart/form-data" method="post"> > > > > <table> > > > > <tr id="auth_user_first_name__row"> > > > > <td><label for="auth_user_first_name" > > > > id="auth_user_first_name__label">First Name: </label></td> > > > > {{if session.action in ["update","create"]:}} > > > > <td><input class="string" id="auth_user_first_name" > > > > name="first_name" type="text" > > > > value="{{=form.custom.inpval.first_name}}" /></td> > > > > {{else:}} > > > > <td>{{=form.custom.inpval.first_name}}</td> > > > > {{pass}} > > > > <td></td></tr> > > > > <tr id="auth_user_last_name__row"> > > > > <td><label for="auth_user_last_name" > > > > id="auth_user_last_name__label">Last Name: </label></td> > > > > {{if session.action in ["update","create"]:}} > > > > <td><input class="string" id="auth_user_last_name" name="last_name" > > > > type="text" value="{{=form.custom.inpval.last_name}}" /></td> > > > > {{else:}} > > > > <td>{{=form.custom.inpval.last_name}}</td> > > > > {{pass}} > > > > <td></td></tr> > > > > <tr id="auth_user_email__row"><td> > > > > <label for="auth_user_email" id="auth_user_email__label">Email: </ > > > > label></td> > > > > {{if session.action in ["update","create"]:}} > > > > <td><input class="string" id="auth_user_email" name="email" > > > > type="text" value="{{=form.custom.inpval.email}}" /></td> > > > > {{else:}} > > > > <td>{{=form.custom.inpval.email}}</td> > > > > {{pass}} > > > > <td></td></tr> > > > > {{if session.action == "update":}} > > > > <tr id="delete_record__row"> > > > > <td><label for="delete_record" id="delete_record__label">Check to > > > > delete:</label></td> > > > > <td><input class="delete" id="delete_record" > > > > name="delete_this_record" type="checkbox" value="off" /></td> > > > > <td></td></tr> > > > > {{pass}} > > > > </table> > > > > {{include 'buttons.html'}} > > > > > On May 3, 10:13 pm, dlypka <dly...@gmail.com> wrote: > > > > > > Well you've done me a great service by creating this sample. > > > > > > I went a bit further and got some partial success by just changing > > > > > this one line: > > > > > > <tr id="testtable_testfield1__row"> > > > > > <td> > > > > > <label for="testtable_testfield1" > > > > > id="testtable_testfield1__label">Testfield1: </label> > > > > > </td> > > > > > {{if session.action == "update":}} > > > > > <td> > > > > > > {{ =INPUT(_type='text', _id='testtable_testfield1', > > > > > _name='testfield1', value="abc", requires=IS_NOT_EMPTY())}} <--- > > > > > This is the changed line > > > > > > </td> > > > > > {{elif session.action == "create":}} > > > > > > This now causes both 'testfield1' fields to mirror each other. > > > > > Well, now we have 2 fields with the same name 'testfield1', so that is > > > > > not too great. > > > > > We would need a way to tell CRUD to NOT call INPUT > > > > > I also have not figured out how to set value = to the actual current > > > > > field value. > > > > > > I'll keep working at it in my spare time.. > > > > > > On May 3, 9:15 pm, Gary <gary.k.ma...@gmail.com> wrote: > > > > > > > Folks, > > > > > > > I've taken note of your comments and work to help me with this. > > > > > > Although I'm afraid that I don't have the skills to participate, I > > > > > > really appreciate your efforts. > > > > > > > Kindest regards, > > > > > > Gary > > > > > > > On May 3, 8:59 pm, dlypka <dly...@gmail.com> wrote: > > > > > > > > FYI > > > > > > > If someone tries to run your code on a fresh empty db, > > > > > > > then they need to first > > > > > > > create a record in the database > > > > > > > and im that case, the record would have id=1 > > > > > > > and so in your code > > > > > > > > def testdata(): > > > > > > > setsubmit() > > > > > > > if request.args: id = request.args[0] > > > > > > > else: id = 3 # Included for testing > > > > > > > > It should be > > > > > > > > def testdata(): > > > > > > > setsubmit() > > > > > > > if request.args: id > > ... > > read more » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---