Hello,

I am facing an error when using web2py sqlform.grid that I am not 
understanding why.

I have the controller where I define the form:

def search_records():

    if request.vars:
        selectable = request.vars.z
        DBconn = db._uri

        name = searchtable(selectable)

        try:
            form = SQLFORM.grid(query=name, orderby=None, searchable=True, 
sortable=True, paginate=20, deletable=True,
                            editable=True, details=True, selectable=None, 
user_signature=False, create=True, csv=False,
                            links=None, links_in_grid=True, maxtextlength=100, 
sorter_icons=('[^]', '[v]'),
                            ui='jquery-ui', showbuttontext=True, 
_class="web2py_grid", formname='web2py_grid',
                            search_widget='default', ignore_rw=True)

            response.view = 'default/search_records.html'

        except:
            redirect(URL('default', 'index'))


    return dict(form=form, selectable=selectable)


the function searchtable returns the table to present in the grid, so the 
variable name is spmething like: db.TABLE_TO_PRESENT

The view page returns what is expected with the respective links "add 
record", "view", "edit" and "delete. The error comes when I use the link 
"add record" or "edit". After opining the correct page to insert the data, 
when clicking submit it shows the error:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

Traceback (most recent call last):
  File "...\web2py\gluon\restricted.py", line 227, in restricted
    exec ccode in environment
  File ".../applications/Mappings/controllers/search_records.py" 
<http://127.0.0.1:8000/admin/default/edit/Mappings/controllers/search_records.py>,
 line 44, in <module>
  File "...\web2py\gluon\globals.py", line 417, in <lambda>
    self._caller = lambda f: f()
  File ".../web2py/applications/Mappings/controllers/search_records.py" 
<http://127.0.0.1:8000/admin/default/edit/Mappings/controllers/search_records.py>,
 line 36, in search_records
    return dict(form=form, selectable=selectable)
UnboundLocalError: local variable 'form' referenced before assignment


So it seems that it loses the information relative to that form that was 
previously loaded.

I am trying to understand the reason for this but I can't get to any 
conclusion. Can anyone help me?

Thank you.



-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to