SQLFORM grid process not working

603 views
Skip to first unread message

Yebach

unread,
Jul 21, 2014, 6:43:00 AM7/21/14
to web...@googlegroups.com
Hello

I have a SQLForm.grid. 

I want to create a response.flash message but on my if evaluation I get an error when my edit view is done

<type 'exceptions.AttributeError'> 'DIV' object has no attribute 'process'

even on my sqlform.grid view

this is my controller function

         form = SQLFORM.grid(query=query, 
left=db.status.on(db.worker.w_status == db.status.id),
fields=fields,  searchable=True, orderby=default_sort_order,create=True,
deletable=True, editable=True, paginate=25, buttons_placement = 'right')
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill the form'
    # Note: no form instance is passed to the view
return dict(form=form)

Anthony

unread,
Jul 21, 2014, 8:13:10 AM7/21/14
to web...@googlegroups.com
Do not call the .process method on a grid -- it automatically does the processing itself. If you don't like the default flash messages, you can do:

if form.accepted:

or:

SQLFORM.grid(..., formargs=dict(message_onsuccess='form accepted',
                           
    message_onfailure='form has errors'))


Anthony

Vid Ogris

unread,
Jul 21, 2014, 8:23:16 AM7/21/14
to web...@googlegroups.com
Thank you on fast reply

How do I present this message in my view?


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/2ikYrc84qB4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Lep pozdrav 

Vid Ogris


Anthony

unread,
Jul 21, 2014, 10:05:10 AM7/21/14
to web...@googlegroups.com
The message is in response.flash, so you need to display that in your view somewhere (it is already present in the layout.html of the scaffolding app).

Anthony
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Vid Ogris

unread,
Jul 22, 2014, 2:15:25 AM7/22/14
to web...@googlegroups.com
If I use 
if form.accepted:

I still get an error 

<type 'exceptions.AttributeError'> 'DIV' object has no attribute 'accepted'


I put <div class="flash">{{=response.flash}}</div> in my view


To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Vid Ogris

unread,
Jul 22, 2014, 2:35:07 AM7/22/14
to web...@googlegroups.com
Looks like everything I do with form.* after I declare it in my controller I get an error

What am I doing wrong here?

Massimo Di Pierro

unread,
Jul 22, 2014, 2:46:59 AM7/22/14
to web...@googlegroups.com
you say form = SQLFORM.grid(....) but this is not a form, this is a grid even if you call it form. Therefore there is no form.process(), there is no form.accepted, there is no form.errors etc. This if not a form.

A grid MAY contain a form so you should do:

grid = SQLFORM.grid()
if grid.create_form:
     if grid.create_form.errors:
           ....
elif grid.update_form:
     if grid.update_form.errors:
           ...

NEVER call process() for these forms. The grid process them automatically and you should never process() twice.
Lep pozdrav 

Vid Ogris


Anthony

unread,
Jul 22, 2014, 7:45:16 AM7/22/14
to web...@googlegroups.com
Sorry, forgot that you have to extract the form from the grid object. You can also get the create and update forms via:

form = grid.element('.web2py_form')

Note, that will be None if there is no form (e.g., when loading just the grid), so first test that it exists.

Anthony

Yebach

unread,
Oct 6, 2015, 10:18:29 PM10/6/15
to web2py-users
Hello

I have a new problem with my forms.

I have validators on the fields

But looks like they are not triggered, so for example

When I insert a new record a first check should be done on the fields like is_not_empty etc.

Then if that is all ok it has to check the field sh_code and if this code already exist in the database i want  a redirect link 

so far the link and everything works ok, but the first validators are not working so i get an error cos the sh_.field which is autogenerate is not done


this is the part of the code that creates a link for flash msg

if (grid_shifts.create_form and grid_shifts.create_form.errors) or (grid_shifts.update_form and grid_shifts.update_form.errors):
 codeField
= grid_shifts.element('input[name=sh_code]')['value']
 
 shiftId
= db(db.shifts.sh_code == codeField).select(db.shifts.id).as_list()
 redId
=  shiftId[0]["id"]
 URL
('turnusi/edit/shifts', args= redId)
 
'static','js/web2py-bootstrap3.js'
 session
.flash= A(T("Click here if you want to activate shift with that code or if you want to be redirected to the shift."), _href=URL('turnusi/edit/shifts', args= redId))

 

validators

db.shifts.sh_name.requires = [IS_NOT_EMPTY(error_message=T('Missing shift name'))]
db.shifts.sh_color.requires = [IS_NOT_EMPTY(error_message=T('Missing shift color'))]
db.shifts.sh_start1.requires = [IS_NOT_EMPTY(error_message=T('Missing start time of the shift'))]
db.shifts.sh_end1.requires = [IS_NOT_EMPTY(error_message=T('Missing end time of the shift'))]






To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Lep pozdrav 

Vid Ogris


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/2ikYrc84qB4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Lep pozdrav 

Vid Ogris


Yebach

unread,
Oct 6, 2015, 10:22:59 PM10/6/15
to web2py-users
Hello

I have a new problem with my forms.

I have validators on the fields

But looks like they are not triggered, so for example

When I insert a new record a first check should be done on the fields like is_not_empty etc.

Then if that is all ok it has to check the field sh_code and if this code already exist in the database i want  a redirect link 

so far the link and everything works ok, but the first validators are not working so i get an error cos the sh_.field which is autogenerate is not done


this is the part of the code that creates a link for flash msg

if (grid_shifts.create_form and grid_shifts.create_form.errors) or (grid_shifts.update_form and grid_shifts.update_form.errors):
 codeField
= grid_shifts.element('input[name=sh_code]')['value']
 
 shiftId
= db(db.shifts.sh_code == codeField).select(db.shifts.id).as_list()
 redId
=  shiftId[0]["id"]
 URL
('turnusi/edit/shifts', args= redId)
 
'static','js/web2py-bootstrap3.js'
 session
.flash= A(T("Click here if you want to activate shift with that code or if you want to be redirected to the shift."), _href=URL('turnusi/edit/shifts', args= redId))

 

validators

db.shifts.sh_name.requires = [IS_NOT_EMPTY(error_message=T('Missing shift name'))]
db.shifts.sh_color.requires = [IS_NOT_EMPTY(error_message=T('Missing shift color'))]
db.shifts.sh_start1.requires = [IS_NOT_EMPTY(error_message=T('Missing start time of the shift'))]
db.shifts.sh_end1.requires = [IS_NOT_EMPTY(error_message=T('Missing end time of the shift'))]

If there is sh_start1 there has to be a sh_end1, because this way i generate sh_code field with javascript

Do you think i should create the value for sh_code field on server or on client?

Anthony

unread,
Oct 7, 2015, 8:12:31 AM10/7/15
to web2py-users
so far the link and everything works ok, but the first validators are not working so i get an error cos the sh_.field which is autogenerate is not done

if (grid_shifts.create_form and grid_shifts.create_form.errors) or (grid_shifts.update_form and grid_shifts.update_form.errors):

Are you saying that even when some fields are left empty, the above condition is nevertheless false (i.e., no form errors) and the following code therefore does not run?

Also, how about something like:

form = grid_shifts.create_form or grid_shifts.update_form
if form and form.errors:


 codeField = grid_shifts.element('input[name=sh_code]')['value']

Instead, how about:

    codeField = form.vars.sh_code


 
 shiftId
= db(db.shifts.sh_code == codeField).select(db.shifts.id).as_list()
 redId
=  shiftId[0]["id"]

No need for .as_list() or the dictionary syntax -- just do:

    redId = db(db.shifts.sh_code == codeField).select().first().id

 
session.flash= A(T("Click here if you want to activate shift with that code or if you want to be redirected to the shift."), _href=URL('turnusi/edit/shifts', args= redId))

Why are you using session.flash -- is there a redirect after this?

Anthony

Vid Ogris

unread,
Oct 7, 2015, 11:11:27 PM10/7/15
to web...@googlegroups.com
thanx for this

Yes I have a redirect to another page.

So if user creates a shift that already exists (code is based on times of duration), i want to give him a choice to go to that shift and activate it in case its status is archived

do you recommend another way. I give now flash message but if i could do smth else it is also ok

thank you again 

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/2ikYrc84qB4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony

unread,
Oct 8, 2015, 1:07:21 AM10/8/15
to web2py-users
I suppose that's fine -- it just wasn't clear to where you were redirecting or why.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Andrew Rogers

unread,
Mar 6, 2020, 9:51:03 AM3/6/20
to web2py-users
Many thanks to you guys for answering so many user questions. I am finding it really helpful.

Cheers
Andrew 
Reply all
Reply to author
Forward
0 new messages