This is what can be done in PHP.  It was easy to build names for
session variables by string concatenation because PHP variables begin
with a dollar sign.  So something like $_SESSION[$foobar] = 'hello,
world' would work. I'm not smart enough yet in Python to know if the
same thing is possible.

That said, here's a solution:

Look for a variable called tab_id to the query string.

if it's there, append it to the query string for the next request.

If it's missing assume it's either a brand new Web2py session or a
fresh browser tab.  In that case, append a new, unique to the query
string.

If you have to park something in the session, concat the tab_id to the
name of the session variable.  If you need to get it back, do the same
concatenation.

Maybe something like session.myvariable%s %tab_id would work.

Didn't depend on the browser at all.

I did not invent this, by the way, so credit belongs elsewhere.

On Oct 27, 1:41 pm, Massimo Di Pierro <[email protected]>
wrote:
> There is not one because this behavior is browser dependent and cannot
> be controller by the server.
> That said. If you know something we do not know let us know and we can
> try improve it.
>
> On Oct 27, 8:54 am, Cliff <[email protected]> wrote:
>
>
>
>
>
>
>
> > What is the Web2py way of making session variables unique to one
> > browser tab?  This example illustrates the problem.
>
> > Model:
> > db.define_table('products', Field('quantity_on_hand', 'integer'))
> > db.define_table('jobs', Field('job_yield', 'integer'),
> > Field('product_id', db.products))
>
> > When a user updates the job_yield field, the jobs controller also
> > needs to update quantity on hand in the products table.  Usually one
> > would use a session variable something like this.
>
> > def edit():
> >     # fetch current job yield
> >     old_job_yield = db.jobs[request.vars(0)].job_yield
> >     # save it in a session
> >     session.old_job_yield= old_job_yield
> >     ...
> >     if form.accepts(session,request):
> >           if request.post_vars.job_yield != session.old_job_yield:
> >                yield_delta = request.post_vars.job_yield -
> > session.old_job_yield
> >                # assume we magically fetch related product id, then
> >                old_quantity_on_hand =
> > db.products[product_id].quantity_on_hand
> >                new_quantity_on_hand = old_quantity_on_hand +
> > yield_delta
>
> > db(db.products.id==product_id).update(quantity_on_hand=new_quantity_on_hand 
> > )
>
> > The problem arises if the user edits a different job in a different
> > tab.  Because there is only one instance of session.old_job_yield, the
> > edit action in the other tab will overwrite it.
>
> > What is the Web2py way of handling this problem?
>
> > Thanks,
> > Cliff Kachinske

Reply via email to