Thanks so much again.

I pasted in the bits of code you demonstrated, which I was missing
and voila, now the validation works with crud() using Gary's custom
form!

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 = request.args[0]
> > > > > >     else: id = 1   # default to read the first record
>
> > > > > > On May 3, 8:16 pm, dlypka <dly...@gmail.com> wrote:
>
> > > > > > > The objects in gluon/html.py appear to be what I would call 
> > > > > > > 'controls'
> > > > > > > whereas the objects in gluon\sqlhtml.py are 'widgets'.
>
> > > > > > > So I see that Crud uses controls and SQLFORM uses widgets.
>
> > > > > > > I am hoping to find a way to use a control in the View markup 
> > > > > > > rather
> > > > > > > than in the Controller.
> > > > > > > I believe that is what Gary needs to do.
>
> > > > > > > On May 3, 7:48 pm, Álvaro Justen [Turicas] 
> > > > > > > <alvarojus...@gmail.com>
> > > > > > > wrote:
>
> > > > > > > > On Sun, May 3, 2009 at 7:32 PM, dlypka <dly...@gmail.com> wrote:
>
> > > > > > > > > because **inside**  the crud()  call I believe it (magically) 
> > > > > > > > > does
> > > > > > > > > this kind of stuff:
>
> > > > > > > > > def test():
> > > > > > > > >    f = FORM('Is web2py cool? Why?',
> > > > > > > > >            SELECT(OPTION('Yes', _value='y'), OPTION('No',
> > > > > > > > > _value='n'), _name='opts', requires=IS_IN_SET(['y'],
> > > > > > > > > error_message='Errr...wrong answer')),
> > > > > > > > >            INPUT(_type='text', _name='why', _value="'cause 
> > > > > > > > > python
> > > > > > > > > rules", requires=IS_NOT_EMPTY()),
> > > > > > > > >            INPUT(_type='submit', _name='btnSubmit', 
> > > > > > > > > _value='ok'))
> > > > > > > > >    if f.accepts(request.vars):
> > > > > > > > >        response.flash = 'form accepted'
> > > > > > > > >    elif request.vars.btnSubmit:
> > > > > > > > >        response.flash = 'error in form'
> > > > > > > > >    return dict(myform=f, v=request.vars)
>
> > > > > > > > > so in particular crud() generates those INPUT objects for 
> > > > > > > > > you, and the
> > > > > > > > > INPUT object is the thing which
> > > > > > > > > creates the error attribute inside that INPUT object instance 
> > > > > > > > > which
> > > > > > > > > then satisfies 'hasattr()'  So I believe the solution for you 
> > > > > > > > > is to
> > > > > > > > > make an INPUT call yourself within the markup, in {{ }} 
> > > > > > > > > (somehow).
> > > > > > > > > Probably we need to modify the INPUT class Python code
> > > > > > > > > to support that.  Basically you need to bind your own 
> > > > > > > > > instance of an
> > > > > > > > > INPUT class, to the part of your form where you need the 
> > > > > > > > > <input> tag.
>
> > > > > > > > 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.
>
> > > > > > > > --
> > > > > > > >  Álvaro Justen
> > > > > > > >  Peta5 - Telecomunicações e Software Livre
> > > > > > > >  21 3021-6001 / 9898-0141
> > > > > > > >  http://www.peta5.com.br/-Hidequotedtext-
>
> > > > > > > > - Show quoted text -- Hide quoted text -
>
> > > > > > > - Show quoted text -- Hide quoted text -
>
> > ...
>
> > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to