I am brand new to web2py and relatively new to python and I'm stuck, mainly 
on a python issue.

My goal is to have a self-submitting form that allows a user to re-submit 
the same simple form any number of times, capture the inputs each time and 
display a list of the values entered, with the intent of acting on those 
values when the user is done adding them.  The filters will essentially be 
where clause statements to execute a long running query, but I'm stuck on 
the form aspects.

As you can see below, I use session.no_filters(number of filters) to change 
the name of the form elements each time.  I then try to use the dict update 
method to add the request.vars dict to the dict that is supposed to hold 
all the values (session.filter_list).  The problem is that in the piece 
I've called out here, I always hit the AttributeError.  I know that x={1:2} 
y={2:3} x.update(y) makes x={1: 2, 2: 3}, so from my perspective, this 
should work,  but I don't know what I'm talking about so...please help.

This is the piece that doesn't work, called out from the below full code 
listing for this piece.
if form.accepts(request,session):
        session.no_filters = session.no_filters+1
        try:
            session.filter_list.update(request.vars)
        except NameError:
            session.filter_list = request.vars
        except AttributeError:
            session.filter_list = 'This is an attribute error' 


Controller code for add_filters
def add_filters():
    try:
        session.no_filters
    except NameError:
        session.no_filters = 0
    
    response.flash="add filters"
    #rows= db().select(db.tablecols.ALL)
    
    form = FORM(        
    TR(LABEL('Filter Source'), \
                      SELECT(
                      _name='filter_src' + str(session.no_filters))),
    TR(LABEL('Operator'), \
                      SELECT(
                          OPTION('='),
                          OPTION('<'),
                          OPTION('>'),
                          OPTION('in'),
                          _name='operator' + str(session.no_filters))),
    TR(LABEL('Value'),INPUT(_name='value')),
    INPUT(_type='submit',_value='Save Filter'),
    INPUT(_type='button',_value='Add Filter',_onclick='addfilter2'),
    INPUT(_type='button',_value='Create Segments',_onclick='createsegment'))
    
    
   
    
    # if form correct, perform the insert
    if form.accepts(request,session):
        session.no_filters = session.no_filters+1
        try:
            session.filter_list.update(request.vars)
        except NameError:
            session.filter_list = request.vars
        except AttributeError:
            session.filter_list = 'This is an attribute error'
    elif form.errors:
        response.flash="form is invalid"
    else:
        response.flash="please fill in the form"
    return dict(form=form,output=form.vars)  


The view code is really just:
{{=BEAUTIFY(session.filter_list)}}

Thanks in advance!


Reply via email to