I've manage to use this solution:

    firstcheck=datetime.fromtimestamp(float(request.args(1)))
    session.id=session.id or {}
    if not post_id in session.id:
        session.id[post_id]=firstcheck
    lastcheck=str(session.id[post_id])
    if str(firstcheck)<lastcheck:
        firstcheck=lastcheck

and then query the db for posts created after > firstcheck

if returns any results:

    session.id[post_id]=str(request.now)





On Feb 1, 8:27 pm, Francisco Costa <m...@franciscocosta.com> wrote:
> I'm trying to do a realtime commenting system.
> I have this place for comments in posts, and I want the new comments
> to display automatically in the comments area, with reloading the
> page.
>
> I have this that check if there are new posts after the page is loaded
> every ten seconds:
>     setInterval("ajax('{{=URL(r=request, f='last_comments',
> args=post_id)}}/{{=time()}}', ['comment'], ':eval');", 10000);
>
> I then use request.args(1) to query the db if there are post created
> after the load.
>
> But if it finds a new post, i have to save in the session the new time
> for cheking..
>
> It works well, but i need to have the post_id in the session variable,
> because if the user as 2 posts loaded, I want the correct comments to
> be displayed in the correct posts.
>
> I don't know if this is the best way, if you any other option please
> let me know.
>
> On Feb 1, 8:15 pm, Jonathan Lundell <jlund...@pobox.com> wrote:
>
>
>
>
>
>
>
> > On Feb 1, 2011, at 11:54 AM, Francisco Costa wrote:
>
> > > the problem is when i open a second tab, it copies the session.id and
> > > doesn't recognize the new page_id
>
> > > basically what i want is a diferrent session.id[page_id] for each tab
> > > i open
>
> > where is page_id coming from? Perhaps the intended code is:
>
> > session.id = session.id or {}
> > session.id['page_id'] = session.id.get('page_id', str(request.now))
>
> > But yes, the problem with this is that you'll always get the same page id 
> > within a session.
>
> > I see a couple more problems as well. You don't actually see "pages" or 
> > "tabs"; you just see requests. So a reload of a page is indistinguishable 
> > from opening the same page in a new tab.
>
> > Also, you have no way of knowing when a page is closed. So if you keep a 
> > dict of open pages in your session, it'll grow indefinitely, which could 
> > result in a rather large session file.
>
> > What are you really trying to do?
>
> > > On Feb 1, 5:19 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
> > > wrote:
> > >> session.id = session.id or {}
> > >> session.id[page_id]=session.id.get(page_id,str(request.now))
>
> > >> On Feb 1, 9:59 am, Francisco Costa <m...@franciscocosta.com> wrote:
>
> > >>> I want something like this:
>
> > >>>     if not session.id[page_id]:
> > >>>         session.id[page_id]=str(request.now)
>
> > >>> but i get this error: KeyError: '74'
>
> > >>> I want to validate if a dynamic variable exists.. if not I want to
> > >>> create it and to get the time
>
> > >>> On Feb 1, 4:17 am, Jason Brower <encomp...@gmail.com> wrote:
>
> > >>>> You can do that. At the top of the default.py or what ever you are 
> > >>>> using, place something like...
> > >>>> session.pages[request.page]  = True
> > >>>> or how ever you want to do it. Just make sure because it is a 
> > >>>> dictionary that you blank it or initialize it befor asigning anything 
> > >>>> to it.
>
> > >>>> ----- Original message -----
> > >>>>> Hello,
> > >>>>> I want to have dinamic session variables like this:
> > >>>>>          session.id
> > >>>>> where id is different from page to page..
>
> > >>>>> I've tried
> > >>>>>          id = variable
> > >>>>>          session.id
>
> > >>>>> and
> > >>>>>          session.id['variable']
>
> > >>>>> without any results.
>
> > >>>>> I would like to be able to open different pages at the same time and
> > >>>>> the browser could get all the session variables.- Hide quoted text -
>
> > >>> - Show quoted text -

Reply via email to