I rewrote my db and forms a bit and am now getting the following:

Traceback (most recent call last):
  File "/Users/mellis/sources/trunk/python/web2py/gluon/
restricted.py", line 107, in restricted
    exec ccode in environment
  File "/Users/mellis/sources/trunk/python/web2py/applications/init/
controllers/default.py", line 182, in <module>
  File "/Users/mellis/sources/trunk/python/web2py/gluon/globals.py",
line 100, in <lambda>
    self._caller = lambda f: f()
  File "/Users/mellis/sources/trunk/python/web2py/applications/init/
controllers/default.py", line 95, in askuser
    if form.accepts(request.vars,session):
  File "/Users/mellis/sources/trunk/python/web2py/gluon/sqlhtml.py",
line 655, in accepts
    onvalidation,
  File "/Users/mellis/sources/trunk/python/web2py/gluon/html.py", line
900, in accepts
    status = self._traverse(status)
  File "/Users/mellis/sources/trunk/python/web2py/gluon/html.py", line
296, in _traverse
    newstatus = c._traverse(status) and newstatus
  File "/Users/mellis/sources/trunk/python/web2py/gluon/html.py", line
296, in _traverse
    newstatus = c._traverse(status) and newstatus
  File "/Users/mellis/sources/trunk/python/web2py/gluon/html.py", line
296, in _traverse
    newstatus = c._traverse(status) and newstatus
  File "/Users/mellis/sources/trunk/python/web2py/gluon/html.py", line
296, in _traverse
    newstatus = c._traverse(status) and newstatus
  File "/Users/mellis/sources/trunk/python/web2py/gluon/html.py", line
303, in _traverse
    newstatus = self._validate()
  File "/Users/mellis/sources/trunk/python/web2py/gluon/html.py", line
713, in _validate
    (value, errors) = validator(value)
TypeError: 'IS_NOT_EMPTY' object is not iterable

Here is the db model.  What I'm trying to do is store 4 items in the
"config" table each time an operators starts a test session.  I'm
trying to require that the field values he/she enters come from a
corresponding single column table (well, 2 columns counting the auto-
id). If the entry is not in the table, then I want to send him/her to
a page that allows a new entry to be entered into the table.  Hence,
each field in the "config" table requires IS_IN_DB() in the
corresponding field in the table that contains permitted values and
each of the permitted values requires IS_NOT_IN_DB to validate
uniqueness. NOTE: the try/except clauses seem to be the cleanest way
around a problem in the Nokia N800 environment. The define_table
statements throw an error in that environment if the table exists.

try:
    ## This table records the user, boot, ip, and port used in
    ## each testing session.
    db.define_table('config',SQLField('user_name','string'),
                        SQLField('boot_type','string'),
                        SQLField('base_device_ip','string'),
                        SQLField('base_device_port', 'integer'),
                        migrate='config.table'
                )
except:
    pass
try:
    ## These tables contain the allowed values for user, boot, ip, and
port
    db.define_table('users',SQLField
('user_name','string',unique=True),
                                        migrate='users.table'
                )
except:
    pass
try:
    db.define_table('boot',SQLField('boot_type','string',unique=True),
                                        migrate='boot.table'
                )
except:
    pass
try:
    db.define_table('ip',SQLField
('base_device_ip','string',unique=True,default='192.168.1.20'),
                                        migrate='ip.table'
                )
except:
    pass
try:
    db.define_table('port',SQLField
('base_device_port','string',unique=True),
                                        migrate='ip.table'
                )
except:
    pass

db.config.user_name.requires = [IS_NOT_EMPTY(), IS_IN_DB(db,
'users.user_name')]
db.users.user_name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
'users.user_name')]
db.config.boot_type.requires = [IS_NOT_EMPTY, IS_IN_DB(db,
'boot.boot_type')]
db.boot.boot_type.requires = [IS_NOT_EMPTY, IS_NOT_IN_DB(db,
'boot.boot_type')]
db.config.base_device_ip.requires = [IS_NOT_EMPTY, IS_IN_DB(db,
'ip.base_device_ip')]
db.ip.base_device_ip.requires = [IS_NOT_EMPTY, IS_NOT_IN_DB(db,
'ip.base_device_ip')]
db.config.base_device_port.requires = [IS_NOT_EMPTY, IS_IN_DB(db,
'port.base_device_port')]
db.port.base_device_port.requires = [IS_NOT_EMPTY, IS_NOT_IN_DB(db,
'port.base_device_port')]


Finally, here are the two controller functions of interest. The error
trace is pointing at the "if form.accepts ..." line in the first
function.  The error is thrown after I enter data in the form and
click submit.

def askuser():
    """
    Asks for operator name , boot type, ip address, port.
    """
    global env
    form=SQLFORM(db.config)
    if form.accepts(request.vars,session):
        response.flash='form accepted'
        env['CONFIGURED'] = True
        logging.info("FORM ACCEPTED")
        logging.info("in askuser(): CONFIGURED = %s"%repr
(env.CONFIGURED))
        redirect(URL(r=request,f='_configinit'))
    elif form.errors:
        response.flash='form has errors'
        logging.info("FORM HAS ERRORS")
        redirect(URL(r=request, f='asknewuser'))
    else:
        response.flash='please fill the form'
    return dict(form=form)


def asknewuser():
    """
    We get sent here if the operator enters a name not already
    in the database
    """
    form = SQLFORM(db.users)
    if form.accepts(request.vars.session):
        redirect(URL(r=request,f=askuser))
    elif form.errors:
        response.flash='form has errors'
        logging.info("FORM HAS ERRORS")
        redirect(URL(r=request, f='askuser'))
    else:
        response.flash='please fill the form'
    return dict(form=form)

Thanks,
Mike

On Jun 29, 2:59 pm, MikeEllis <michael.f.el...@gmail.com> wrote:
> Hmmm ...
> I may want to rethink the db and interface design a bit.  There are
> only 4 items that the operator needs to enter at the beginning of the
> test session: a name, an equipment identifier, an ip address, and a
> port number.  There are not all that many possible values for any of
> these items (except the ip address).
>
> It might make or sense for me to present a sequence of forms, one for
> each item. If the operator tries to enter something not in the db,  I
> could redirect to a page that asks for confirmation and does the
> insert.  Is there a way to access the value they tried to enter within
> the form.errors clause?
>
> Thanks!
> Mike
>
> On Jun 29, 2:30 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > something like this
>
> > def mywidget(field, value):
> >       return INPUT(_name='field', _id='table_field',
> > _class='fieldtype', _value=value)
> > db.table.field.widget=mywidget
>
> > but in your case mywidget should return a table containing a select
> > box obtained from selecting the records and an entry field (to add an
> > option).
> > This is not too easy although possible.
>
> > Massimo
>
> > On Jun 29, 1:23 pm, MikeEllis <michael.f.el...@gmail.com> wrote:
>
> > > Massimo,
> > > Thanks for the quick reply! Yes, it's the same field I need to
> > > validate.  Can you steer me toward docs and/or examples of creating my
> > > own validator and widget? (I have a copy of your manual).
> > > Mike
>
> > > On Jun 29, 2:16 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > It is possible but you would need to create your own validator and
> > > > wdget for that.
>
> > > > Is the "unique items in a given field" the same field you need to
> > > > validate?
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to