With just "if form.create_form:" It works finally... Maybe I was having other typo in my code that raise error then since I was focusing on the problem I didn't realise that it was for other reason...
At that I had table = SQLFORM.grid(...) and was verifying : "if form.create_form:" So for sure it wasn't there it was in table... It should had been "if table.create_form:" So if create_form is always there as long as form exist don't need the "if 'new' in request.args:" Richard On Thu, Nov 10, 2011 at 4:10 PM, Anthony <[email protected]> wrote: > My mistake -- looks like it always has a .create_form, but set to None in > other cases. But in that case: > > if form.create_form: > > should work, though I think you said that didn't work -- what happened > when you tried that? > > Anthony > > > On Thursday, November 10, 2011 4:04:00 PM UTC-5, Richard wrote: > >> Ok but it's not seem to work... I get this error trace back : >> >> 1. >> 2. >> 3. >> 4. >> 5. >> 6. >> 7. >> 8. >> 9. >> 10. >> >> Traceback (most recent call last): >> >> File "/web2py/gluon/restricted.py", line 194, in restricted >> >> exec ccode in environment >> >> File "/web2py/applications/sgddms/**controllers/test.py", line 4437, in >> <module> >> >> File "/web2py/gluon/globals.py", line 149, in <lambda> >> >> self._caller = lambda f: f() >> >> File "/web2py/applications/sgddms/**controllers/test.py", line 4396, in >> test_sqlformgrid >> >> for i in range(0,len(form.create_form[0**])): >> TypeError: 'NoneType' object is unsubscriptable >> >> Any idea? >> >> It really the first time I play with SQLFORM.grid and it not documented >> yet so I may ask kind of trivial question... Also I a bit under pressure. >> >> I really appreciate your help. >> >> Richard >> >> On Thu, Nov 10, 2011 at 3:57 PM, Anthony <[email protected]> wrote: >> >>> I'd go with the second option -- more fool proof. >>> >>> >>> On Thursday, November 10, 2011 3:11:11 PM UTC-5, Richard wrote: >>> >>>> Ok so this : >>>> >>>> "if 'new' in request.args and form.create_form:" >>>> >>>> or shorter : >>>> >>>> "if hasattr(form, 'create_form'):" >>>> >>>> ? >>>> >>>> Thank you. >>>> >>>> Richard >>>> >>>> On Thu, Nov 10, 2011 at 2:58 PM, Anthony <[email protected]> wrote: >>>> >>>>> If you have "if 'new' in request.args:' you should not also need "if >>>>> form.create_form" (even if you did, you could simply put them in the same >>>>> "if" statement with an "and"). Alternatively, use "if hasattr(form, >>>>> 'create_form'):" -- all by itself. >>>>> >>>>> Anthony >>>>> >>>>> >>>>> On Thursday, November 10, 2011 2:48:49 PM UTC-5, Richard wrote: >>>>> >>>>>> Here a working piece of code : >>>>>> >>>>>> def test_sqlformgrid(): >>>>>> form = SQLFORM.grid(db.TABLE, ui='jquery-ui', >>>>>> editable=auth.has_membership('******reviewer'), >>>>>> deletable=auth.has_membership(******'reviewer'), formstyle = 'divs') >>>>>> if 'new' in request.args: >>>>>> if form.create_form >>>>>> for i in range(0,len(form.create_form[**0****])): >>>>>> if len(form.create_form[0][i][2][******0]) > 0: >>>>>> >>>>>> form.create_form[0][i][0].**appe****nd(SPAN((helpicon(), >>>>>> SPAN(form.create_form[0][i][2]******[0])),_class='tooltip')) >>>>>> del(form.create_form[0][i][2]) >>>>>> return dict(form=form) >>>>>> >>>>>> Off course the for i in range... Is specific to my need but it the >>>>>> way to manipulate the generated html form before it goes in user hand... >>>>>> >>>>>> :) >>>>>> >>>>>> Richard >>>>>> >>>>>> On Thu, Nov 10, 2011 at 2:44 PM, Richard Vézina <[email protected]>wrote: >>>>>> >>>>>>> It was working "if form.create_form:"... >>>>>>> >>>>>>> I thought that grid use form variable doesn't matter if the >>>>>>> SQLFORM.grid wasn't in a form variable at all... >>>>>>> >>>>>>> And my bad because I show form = crud... But it was not my >>>>>>> SQLFORM.grid... Arrg. >>>>>>> >>>>>>> Sorry about that... >>>>>>> >>>>>>> Richard >>>>>>> >>>>>>> On Thu, Nov 10, 2011 at 1:26 PM, Anthony <[email protected]> wrote: >>>>>>> >>>>>>>> On Thursday, November 10, 2011 12:42:49 PM UTC-5, Richard wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> "if 'new' in request.args:" works (allow to load the grid) but the >>>>>>>>> "if form.create_form:" not work alone or in conjunction with the >>>>>>>>> former >>>>>>>>> >>>>>>>> >>>>>>>> Yeah, looks like it would have to be something like "if >>>>>>>> hasattr(form, 'create_form'):". >>>>>>>> >>>>>>> >>>>>>> >>>>>> >>>> >>

