Hi Denes,

Instead of an explanation, I'll give you an example, which I hope is
more helpful.

On this page: http://www.apple.com/buy/

When you enter "New York, NY" in the "Find a Reseller" form you're
redirected to:

http://www.apple.com/buy/locator/index.html?q=New+York%2C+NY

... and the store locations near New York are displayed.

When you enter "Washington, DC" in the "Store Locator" form, the URL
still reads like:

http://www.apple.com/buy/locator/index.html?q=New+York%2C+NY

... but, the store locations near Washington are displayed.


Which is about the same behaviour I observe when my default/index and
locator/city functions. In case of the locator/city function I guess
this is what happens:


def city():
    form=SQLFORM.factory(..)
    if request.args:
        rows=db((..)).select(..)
    if form.accepts(request.vars,session,keepvalues=True):
        rows=db((..)).select(..)
    return dict(form=form,rows=rows)

.. both if request.args: and if form.accepts are executed, because
both conditions are true, the results displayed are correct, because
if request.args' rows get overridden by if form.accepts' rows.


What do you think of the following solution:

In the default controller:


def index():
    form1=SQLFORM.factory(..)
    form2=[]
    form3=[]
    if form1.accepts(request.vars,session,formname='form1'):
        session.what=request.vars.what
        session.city=request.vars.city
        redirect(URL(r=request,c='locator',f='city'))
    ...
    return dict(form1=form1,form2=form2,form3=form3)


.. and in the locator controller:


def city():
    form=SQLFORM.factory(..)
    if session.what and session.city:
        rows=db((..)&(db.companykeyword.word==session.what)&\
        (db.address.city==session.city))
        .select(..)
        session.what=session.city=[]
    if form.accepts(request.vars,session,keepvalues=True):
        rows=db((..)&(db.companykeyword.word==request.vars.what)&\
        (db.address.city==request.vars.city))
        .select(..)
    return dict(form=form,rows=rows)




@pbreit,
Thanks for your advise, as you see I set form2 and form3 to be [], and
I am trying to get form1 and form to behave correctly.


Kind regards,

Annet.

Reply via email to