[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Brian Will
Done. Thanks Massimo, and for all your hard work.

On Apr 14, 7:29 am, Massimo Di Pierro 
wrote:
> Please open an issue in google code and I will fix this asap.
>
> On Apr 14, 8:56 am, Brian Will  wrote:
>
>
>
>
>
>
>
> > No, form.vars and request.vars both work the same there. (Should I be
> > using request instead anyway?) The internal error stems from adding
> > 'terms' to form.errors, which then gets looked up as if 'terms' is a
> > field in my table, which it's not. Look at sqlhtml.py line 1042.
>
> > So am I doing this in a way that's supposed to work? Is this an edge
> > case just not accounted for yet?
>
> > On Apr 14, 6:30 am, Massimo Di Pierro 
> > wrote:
>
> > > Because onfailure
>
> > > def validateTerms(form):
> > >             if form.vars.terms != 'agree':
> > >                 form.errors.terms = 'You must agree to the terms.'
>
> > > must be
>
> > > def validateTerms(form):
> > >             if request.vars.terms != 'agree':
> > >                 form.errors.terms = 'You must agree to the terms.'
>
> > > as the request.vars has not yet been copied into form.vars I
> > > think.
>
> > > On Apr 14, 8:18 am, Brian Will  wrote:
>
> > > > I'm trying to add a checkbox that must be ticked to an update SQLFORM,
> > > > but I'm getting an internal error.
>
> > > > Here's the create form that works fine with an added checkbox:
>
> > > >     form = SQLFORM(db.job_post, submit_button='Post Job',
> > > > formstyle='table2cols',
> > > >         fields=['poster_name', 'poster_email', 'poster_phone',
> > > > 'zipcode', 'job_type', 'job_title', 'job_description'],
> > > >         _id='postjob',
> > > >         _class='form2col'
> > > >     )
> > > >     form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms of
> > > > service', _href=URL('terms'))), INPUT(_name='terms', _value='agree',
> > > > _type='checkbox', _style="margin: 0px 0px 4px 14px"  # add
> > > > checkbox
>
> > > >     def validateTerms(form):
> > > >         if form.vars.terms != 'agree':
> > > >             form.errors.terms = 'You must agree to the terms.'
>
> > > >     if form.accepts(request.vars, session, onvalidation={'onsuccess':
> > > > validateTerms, 'onfailure': validateTerms}):
> > > >          # bla bla
>
> > > > Now on another page here's virtually the same thing but an update
> > > > form:
>
> > > > form = SQLFORM(db.job_post, job.id, submit_button='Update Job',
> > > > formstyle='table2cols',
> > > >             fields=['poster_name', 'poster_email', 'poster_phone',
> > > > 'zipcode', 'job_type', 'job_title', 'job_description'],
> > > >             _id='postjob',
> > > >             _class='form2col'
> > > >         )
> > > >         form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms
> > > > of service', _href=URL('terms'))), INPUT(_name='terms',
> > > > _value='agree', _type='checkbox', _style="margin: 0px 0px 4px
> > > > 14px"  # add checkbox
>
> > > >         def validateTerms(form):
> > > >             if form.vars.terms != 'agree':
> > > >                 form.errors.terms = 'You must agree to the terms.'
>
> > > >         if form.accepts(request.vars, session,
> > > > onvalidation={'onsuccess': validateTerms, 'onfailure':
> > > > validateTerms}):
> > > >                       # bla bla
>
> > > > And here's the ticket I get with this second form:
>
> > > > Traceback (most recent call last):
> > > >   File "/home/www-data/web2py/gluon/restricted.py", line 188, in
> > > > restricted
> > > >     exec ccode in environment
> > > >   File "/home/www-data/web2py/applications/staging/controllers/
> > > > default.py", line 329, in 
> > > >   File "/home/www-data/web2py/gluon/globals.py", line 124, in 
> > > >     self._caller = lambda f: f()
> > > >   File "/home/www-data/web2py/applications/staging/controllers/
> > > > default.py", line 119, in post_edit
> > > >     if form.accepts(request.vars, session, onvalidation={'onsuccess':
> > > > validateTerms, 'onfailure': validateTerms}):
> > > >   File "/home/www-data/web2py/gluon/sqlhtml.py", line 1042, in accepts
> > > >     if self.table[key].type == 'upload' \
> > > >   File "/home/www-data/web2py/gluon/dal.py", line 4320, in __getitem__
> > > >     return dict.__getitem__(self, str(key))
> > > > KeyError: 'terms'
>
> > > > Looking at sqlhtml.py line 1042, I see there's a check done for update
> > > > forms that involves looking for every entry in self.errors in
> > > > self.table, which of course won't be found here because my checkbox is
> > > > not part of the table.
>
> > > > If I comment out the assignment to form.errors.terms, I don't get this
> > > > error, but of course then I don't get the validation I want. Also, I
> > > > strangely then get a 'no data' error message for the first field when
> > > > I visit the page but no such error when I submit the form. If I remove
> > > > the onvalidation arg from accepts, this error goes away entirely.
>
> > > > So any ideas? Am I doing things wrong or is there some bug here?


[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Massimo Di Pierro
Please open an issue in google code and I will fix this asap.

On Apr 14, 8:56 am, Brian Will  wrote:
> No, form.vars and request.vars both work the same there. (Should I be
> using request instead anyway?) The internal error stems from adding
> 'terms' to form.errors, which then gets looked up as if 'terms' is a
> field in my table, which it's not. Look at sqlhtml.py line 1042.
>
> So am I doing this in a way that's supposed to work? Is this an edge
> case just not accounted for yet?
>
> On Apr 14, 6:30 am, Massimo Di Pierro 
> wrote:
>
>
>
>
>
>
>
> > Because onfailure
>
> > def validateTerms(form):
> >             if form.vars.terms != 'agree':
> >                 form.errors.terms = 'You must agree to the terms.'
>
> > must be
>
> > def validateTerms(form):
> >             if request.vars.terms != 'agree':
> >                 form.errors.terms = 'You must agree to the terms.'
>
> > as the request.vars has not yet been copied into form.vars I
> > think.
>
> > On Apr 14, 8:18 am, Brian Will  wrote:
>
> > > I'm trying to add a checkbox that must be ticked to an update SQLFORM,
> > > but I'm getting an internal error.
>
> > > Here's the create form that works fine with an added checkbox:
>
> > >     form = SQLFORM(db.job_post, submit_button='Post Job',
> > > formstyle='table2cols',
> > >         fields=['poster_name', 'poster_email', 'poster_phone',
> > > 'zipcode', 'job_type', 'job_title', 'job_description'],
> > >         _id='postjob',
> > >         _class='form2col'
> > >     )
> > >     form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms of
> > > service', _href=URL('terms'))), INPUT(_name='terms', _value='agree',
> > > _type='checkbox', _style="margin: 0px 0px 4px 14px"  # add
> > > checkbox
>
> > >     def validateTerms(form):
> > >         if form.vars.terms != 'agree':
> > >             form.errors.terms = 'You must agree to the terms.'
>
> > >     if form.accepts(request.vars, session, onvalidation={'onsuccess':
> > > validateTerms, 'onfailure': validateTerms}):
> > >          # bla bla
>
> > > Now on another page here's virtually the same thing but an update
> > > form:
>
> > > form = SQLFORM(db.job_post, job.id, submit_button='Update Job',
> > > formstyle='table2cols',
> > >             fields=['poster_name', 'poster_email', 'poster_phone',
> > > 'zipcode', 'job_type', 'job_title', 'job_description'],
> > >             _id='postjob',
> > >             _class='form2col'
> > >         )
> > >         form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms
> > > of service', _href=URL('terms'))), INPUT(_name='terms',
> > > _value='agree', _type='checkbox', _style="margin: 0px 0px 4px
> > > 14px"  # add checkbox
>
> > >         def validateTerms(form):
> > >             if form.vars.terms != 'agree':
> > >                 form.errors.terms = 'You must agree to the terms.'
>
> > >         if form.accepts(request.vars, session,
> > > onvalidation={'onsuccess': validateTerms, 'onfailure':
> > > validateTerms}):
> > >                       # bla bla
>
> > > And here's the ticket I get with this second form:
>
> > > Traceback (most recent call last):
> > >   File "/home/www-data/web2py/gluon/restricted.py", line 188, in
> > > restricted
> > >     exec ccode in environment
> > >   File "/home/www-data/web2py/applications/staging/controllers/
> > > default.py", line 329, in 
> > >   File "/home/www-data/web2py/gluon/globals.py", line 124, in 
> > >     self._caller = lambda f: f()
> > >   File "/home/www-data/web2py/applications/staging/controllers/
> > > default.py", line 119, in post_edit
> > >     if form.accepts(request.vars, session, onvalidation={'onsuccess':
> > > validateTerms, 'onfailure': validateTerms}):
> > >   File "/home/www-data/web2py/gluon/sqlhtml.py", line 1042, in accepts
> > >     if self.table[key].type == 'upload' \
> > >   File "/home/www-data/web2py/gluon/dal.py", line 4320, in __getitem__
> > >     return dict.__getitem__(self, str(key))
> > > KeyError: 'terms'
>
> > > Looking at sqlhtml.py line 1042, I see there's a check done for update
> > > forms that involves looking for every entry in self.errors in
> > > self.table, which of course won't be found here because my checkbox is
> > > not part of the table.
>
> > > If I comment out the assignment to form.errors.terms, I don't get this
> > > error, but of course then I don't get the validation I want. Also, I
> > > strangely then get a 'no data' error message for the first field when
> > > I visit the page but no such error when I submit the form. If I remove
> > > the onvalidation arg from accepts, this error goes away entirely.
>
> > > So any ideas? Am I doing things wrong or is there some bug here?


[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Brian Will
No, form.vars and request.vars both work the same there. (Should I be
using request instead anyway?) The internal error stems from adding
'terms' to form.errors, which then gets looked up as if 'terms' is a
field in my table, which it's not. Look at sqlhtml.py line 1042.

So am I doing this in a way that's supposed to work? Is this an edge
case just not accounted for yet?

On Apr 14, 6:30 am, Massimo Di Pierro 
wrote:
> Because onfailure
>
> def validateTerms(form):
>             if form.vars.terms != 'agree':
>                 form.errors.terms = 'You must agree to the terms.'
>
> must be
>
> def validateTerms(form):
>             if request.vars.terms != 'agree':
>                 form.errors.terms = 'You must agree to the terms.'
>
> as the request.vars has not yet been copied into form.vars I
> think.
>
> On Apr 14, 8:18 am, Brian Will  wrote:
>
>
>
>
>
>
>
> > I'm trying to add a checkbox that must be ticked to an update SQLFORM,
> > but I'm getting an internal error.
>
> > Here's the create form that works fine with an added checkbox:
>
> >     form = SQLFORM(db.job_post, submit_button='Post Job',
> > formstyle='table2cols',
> >         fields=['poster_name', 'poster_email', 'poster_phone',
> > 'zipcode', 'job_type', 'job_title', 'job_description'],
> >         _id='postjob',
> >         _class='form2col'
> >     )
> >     form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms of
> > service', _href=URL('terms'))), INPUT(_name='terms', _value='agree',
> > _type='checkbox', _style="margin: 0px 0px 4px 14px"  # add
> > checkbox
>
> >     def validateTerms(form):
> >         if form.vars.terms != 'agree':
> >             form.errors.terms = 'You must agree to the terms.'
>
> >     if form.accepts(request.vars, session, onvalidation={'onsuccess':
> > validateTerms, 'onfailure': validateTerms}):
> >          # bla bla
>
> > Now on another page here's virtually the same thing but an update
> > form:
>
> > form = SQLFORM(db.job_post, job.id, submit_button='Update Job',
> > formstyle='table2cols',
> >             fields=['poster_name', 'poster_email', 'poster_phone',
> > 'zipcode', 'job_type', 'job_title', 'job_description'],
> >             _id='postjob',
> >             _class='form2col'
> >         )
> >         form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms
> > of service', _href=URL('terms'))), INPUT(_name='terms',
> > _value='agree', _type='checkbox', _style="margin: 0px 0px 4px
> > 14px"  # add checkbox
>
> >         def validateTerms(form):
> >             if form.vars.terms != 'agree':
> >                 form.errors.terms = 'You must agree to the terms.'
>
> >         if form.accepts(request.vars, session,
> > onvalidation={'onsuccess': validateTerms, 'onfailure':
> > validateTerms}):
> >                       # bla bla
>
> > And here's the ticket I get with this second form:
>
> > Traceback (most recent call last):
> >   File "/home/www-data/web2py/gluon/restricted.py", line 188, in
> > restricted
> >     exec ccode in environment
> >   File "/home/www-data/web2py/applications/staging/controllers/
> > default.py", line 329, in 
> >   File "/home/www-data/web2py/gluon/globals.py", line 124, in 
> >     self._caller = lambda f: f()
> >   File "/home/www-data/web2py/applications/staging/controllers/
> > default.py", line 119, in post_edit
> >     if form.accepts(request.vars, session, onvalidation={'onsuccess':
> > validateTerms, 'onfailure': validateTerms}):
> >   File "/home/www-data/web2py/gluon/sqlhtml.py", line 1042, in accepts
> >     if self.table[key].type == 'upload' \
> >   File "/home/www-data/web2py/gluon/dal.py", line 4320, in __getitem__
> >     return dict.__getitem__(self, str(key))
> > KeyError: 'terms'
>
> > Looking at sqlhtml.py line 1042, I see there's a check done for update
> > forms that involves looking for every entry in self.errors in
> > self.table, which of course won't be found here because my checkbox is
> > not part of the table.
>
> > If I comment out the assignment to form.errors.terms, I don't get this
> > error, but of course then I don't get the validation I want. Also, I
> > strangely then get a 'no data' error message for the first field when
> > I visit the page but no such error when I submit the form. If I remove
> > the onvalidation arg from accepts, this error goes away entirely.
>
> > So any ideas? Am I doing things wrong or is there some bug here?


[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Massimo Di Pierro
Because onfailure

def validateTerms(form):
if form.vars.terms != 'agree':
form.errors.terms = 'You must agree to the terms.'

must be

def validateTerms(form):
if request.vars.terms != 'agree':
form.errors.terms = 'You must agree to the terms.'

as the request.vars has not yet been copied into form.vars I
think.

On Apr 14, 8:18 am, Brian Will  wrote:
> I'm trying to add a checkbox that must be ticked to an update SQLFORM,
> but I'm getting an internal error.
>
> Here's the create form that works fine with an added checkbox:
>
>     form = SQLFORM(db.job_post, submit_button='Post Job',
> formstyle='table2cols',
>         fields=['poster_name', 'poster_email', 'poster_phone',
> 'zipcode', 'job_type', 'job_title', 'job_description'],
>         _id='postjob',
>         _class='form2col'
>     )
>     form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms of
> service', _href=URL('terms'))), INPUT(_name='terms', _value='agree',
> _type='checkbox', _style="margin: 0px 0px 4px 14px"  # add
> checkbox
>
>     def validateTerms(form):
>         if form.vars.terms != 'agree':
>             form.errors.terms = 'You must agree to the terms.'
>
>     if form.accepts(request.vars, session, onvalidation={'onsuccess':
> validateTerms, 'onfailure': validateTerms}):
>          # bla bla
>
> Now on another page here's virtually the same thing but an update
> form:
>
> form = SQLFORM(db.job_post, job.id, submit_button='Update Job',
> formstyle='table2cols',
>             fields=['poster_name', 'poster_email', 'poster_phone',
> 'zipcode', 'job_type', 'job_title', 'job_description'],
>             _id='postjob',
>             _class='form2col'
>         )
>         form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms
> of service', _href=URL('terms'))), INPUT(_name='terms',
> _value='agree', _type='checkbox', _style="margin: 0px 0px 4px
> 14px"  # add checkbox
>
>         def validateTerms(form):
>             if form.vars.terms != 'agree':
>                 form.errors.terms = 'You must agree to the terms.'
>
>         if form.accepts(request.vars, session,
> onvalidation={'onsuccess': validateTerms, 'onfailure':
> validateTerms}):
>                       # bla bla
>
> And here's the ticket I get with this second form:
>
> Traceback (most recent call last):
>   File "/home/www-data/web2py/gluon/restricted.py", line 188, in
> restricted
>     exec ccode in environment
>   File "/home/www-data/web2py/applications/staging/controllers/
> default.py", line 329, in 
>   File "/home/www-data/web2py/gluon/globals.py", line 124, in 
>     self._caller = lambda f: f()
>   File "/home/www-data/web2py/applications/staging/controllers/
> default.py", line 119, in post_edit
>     if form.accepts(request.vars, session, onvalidation={'onsuccess':
> validateTerms, 'onfailure': validateTerms}):
>   File "/home/www-data/web2py/gluon/sqlhtml.py", line 1042, in accepts
>     if self.table[key].type == 'upload' \
>   File "/home/www-data/web2py/gluon/dal.py", line 4320, in __getitem__
>     return dict.__getitem__(self, str(key))
> KeyError: 'terms'
>
> Looking at sqlhtml.py line 1042, I see there's a check done for update
> forms that involves looking for every entry in self.errors in
> self.table, which of course won't be found here because my checkbox is
> not part of the table.
>
> If I comment out the assignment to form.errors.terms, I don't get this
> error, but of course then I don't get the validation I want. Also, I
> strangely then get a 'no data' error message for the first field when
> I visit the page but no such error when I submit the form. If I remove
> the onvalidation arg from accepts, this error goes away entirely.
>
> So any ideas? Am I doing things wrong or is there some bug here?