This is kind of a show stopper.  Smartgrid appears to stumble over
table format definitions.

Note the commented out format line in this model.
db.define_table('dog',
                Field('dog_name', length=32),
##                format='%(name)s',
               )
db.define_table('owner',
                Field('name', length=32),
                Field('phone', length=32),
               )
db.define_table('dog_owner',
                Field('dog_id', db.dog),
                Field('owner_id', db.owner)
               )

Uncomment the line and smartgrid 1.99.4 raises this exception when
trying to
add a record to the dog_owner table:
<type 'exceptions.TypeError'> string indices must be integers, not str

Here is the traceback:
Traceback (most recent call last):
  File "/home/cjk/w-99-4/web2py/gluon/restricted.py", line 204, in
restricted
    exec ccode in environment
  File "/home/cjk/w-99-4/web2py/applications/doggies/controllers/
dog.py", line 5, in <module>
  File "/home/cjk/w-99-4/web2py/gluon/globals.py", line 172, in
<lambda>
    self._caller = lambda f: f()
  File "/home/cjk/w-99-4/web2py/applications/doggies/controllers/
dog.py", line 2, in index
    form = SQLFORM.smartgrid(db.dog)
  File "/home/cjk/w-99-4/web2py/gluon/sqlhtml.py", line 1991, in
smartgrid
    user_signature=user_signature,**kwargs)
  File "/home/cjk/w-99-4/web2py/gluon/sqlhtml.py", line 1581, in grid
    _class='web2py_form').process(
  File "/home/cjk/w-99-4/web2py/gluon/sqlhtml.py", line 862, in
__init__
    inp = self.widgets.options.widget(field, default)
  File "/home/cjk/w-99-4/web2py/gluon/sqlhtml.py", line 220, in widget
    return SELECT(*opts, **attr)
  File "/home/cjk/w-99-4/web2py/gluon/html.py", line 587, in __init__
    self._postprocessing()
  File "/home/cjk/w-99-4/web2py/gluon/html.py", line 1704, in
_postprocessing
    if value and str(c['_value'])==str(value):
TypeError: string indices must be integers, not str

Here is the controller:
def index():
    form = SQLFORM.smartgrid(
        db.owner,
        ui = 'jquery-ui',
        onvalidation = crud.archive,
    )
    return dict(form=form)

To duplicate the problem:
Add one owner and one dog.
In your browser, open localhost:8000/dogapp/owner/index
Edit the owner.
Click the Dog Owner link
Note the empty grid with add button.
Click Add
Observe web2py error message

Similar exceptions occur if you use IS_IN_DB to define a format
string.

Reply via email to