auto-update/refresh content

1,307 views
Skip to first unread message

mart

unread,
Apr 5, 2011, 3:51:56 AM4/5/11
to web2py-users
Hi,

I'm trying to do these 2 things:

1)
I have a directory structure which stores sioftware builds (many
builds daily), all versioned and sortable, many products, branches,
blablabla..., alright.

i would like new arrivals to "magically" announce their arrival in
some section of a web page (but without having to refresh the page).
This may at time appear to be scrolling (at least, that's the desired
affect).

2) similar...
each build has a set of logs/reports (most of which is stored in a
DB). I would like to have some of that data follow those magically
appearing build paths and effectively slide down the column along with
the build announcement...


Anybody have an idea? a direction or something to look at for ideas? I
just need the mechanics on how something like that can be setup in a
web page... an alternative would be an embedded Flex app, which can be
easily achieved, but I would rather not go there....


Thanks a bunch in advance,
Mart :)

Ross Peoples

unread,
Apr 5, 2011, 9:58:39 AM4/5/11
to web...@googlegroups.com
One of the most common ways to do this is using JavaScript polling. Every 10 seconds or so, JavaScript would call a controller in your application using AJAX. Your controller would return formatted HTML to be displayed in your new arrivals section. In the view that your new arrivals section is located, you would want to put something similar to this at the bottom of the view:

<script type="text/javascript">
    jQuery(document).ready(function() {
        window.setTimeout(function() {
            var url = '{{=URL('new_arrivals.load')}}';
            jQuery('#new-arrivals').load(url);
        }, 10000);
    });
</script>

This assumes that you have a <div id="new-arrivals"> in your view, and that you have a view named new_arrivals.load. Your controller for new_arrivals should check for new entries in the database, then return those to a view called new_arrivals.load, which should format the rows from the database in the way you want this information displayed in your <div id="new-arrivals"> section.

Hope that helps.

mart

unread,
Apr 5, 2011, 10:16:13 AM4/5/11
to web2py-users
hey Ross,

Thanks, yes that does help ! :)

I think that's my content difficulty (and what also makes it fun!),
taking the leap to thinking "web" :) So, If I understand how this
works is...


1) I can take care of parsing recursively 'new arrivals' anywhere
within a given root directory (this is done).

2) I can take the return value and
A) format some sort of decent looking HTML (ok, easy enough)
B) while the data from item A is loaded, use it in a query, take
that returned data, format it and pass it along with whatever I have
with item A) the javascript

3) The javascript executes/loads the python code on a given interval,
takes the data (which should be handed as HTML) and presents that

If that sums it up, then I'll try it like that.

Thanks for your help!

Mart :)

Ross Peoples

unread,
Apr 5, 2011, 10:31:13 AM4/5/11
to web...@googlegroups.com
That's basically how it works. Although as you learn more about AJAX, you'll find that there are a bunch of different ways to do this, including more 2-way types of communication, where you would do something with the data returned from the controller before or after displaying it on the page. Once you start to open your mind a bit and get the hang of how it all works, you'll start to figure out some really cool ways to tackle problems.

mart

unread,
Apr 5, 2011, 5:21:54 PM4/5/11
to web2py-users
Wow! didn't know that - You know, there is so much out there, that we
(well, me for sure) rarely take the time to discover things fully. I
love that when I know in advance that there is something to be had by
sticking to something and looking deeper than we (me) usually would!

Thanks for the tip, I will certainly look into this :)

Mart

DenesL

unread,
Apr 5, 2011, 7:23:02 PM4/5/11
to web2py-users

There is something called reverse ajax, one site explaining the
technique is
http://www.obviously.com/tech_tips/slow_load_technique

I have not had the need for it but I would like to hear from you if
you get around to use it.

mart

unread,
Apr 5, 2011, 8:01:23 PM4/5/11
to web2py-users
reverse ajax, eh? alright, then I think it should be reversed! :) Of
course I usually start anything with the word "reversed" in it with
large pot of of coffee!

stay tuned!

thanks,
Mart :)

On Apr 5, 7:23 pm, DenesL <denes1...@yahoo.ca> wrote:
> There is something called reverse ajax, one site explaining the
> technique ishttp://www.obviously.com/tech_tips/slow_load_technique

Anthony

unread,
Apr 5, 2011, 9:15:24 PM4/5/11
to web...@googlegroups.com
I think that's another term for Comet, which is just a general term for various server push techniques: http://en.wikipedia.org/wiki/Comet_(programming)
 
Note, if you're using Comet/long-polling techniques, I think it keeps a request open for a long time, so if you're using a server that blocks a thread for each request, you could run out of threads if you have lots of users connected at once. In that case, you may need to look into a non-blocking server that can handle lots of open connections.
 
You might also look at the web2py comet_messaging.py in /gluon/contrib. It uses the new HTML5 WebSockets (so technically I guess it's not actually Comet) and the Tornado web server (which is non-blocking, so can handle lots of open connections). Note, it won't work in older browsers, including IE8 and earlier.
 
Anthony

On Tuesday, April 5, 2011 8:01:23 PM UTC-4, mart wrote:
reverse ajax, eh? alright, then I think it should be reversed! :)  Of
course I usually start anything with the word "reversed" in it with
large pot of of coffee!

stay tuned!

thanks,
Mart :)

David Warnock

unread,
Apr 5, 2011, 9:20:27 PM4/5/11
to web...@googlegroups.com
Note, if you're using Comet/long-polling techniques, I think it keeps a request open for a long time, so if you're using a server that blocks a thread for each request, you could run out of threads if you have lots of users connected at once. In that case, you may need to look into a non-blocking server that can handle lots of open connections.

I guess following the other thread that not blocking with the session would be an especially good idea in this situation.

Dave

--
Dave Warnock: http://42.blogs.warnock.me.uk

mart

unread,
Apr 5, 2011, 9:57:18 PM4/5/11
to web2py-users
Thanks for the replies! :) May be fun to compare... If all goes, i
can do this tonight (maybe)

Thanks guys!

Mart :)

stefaan

unread,
Apr 6, 2011, 7:54:51 AM4/6/11
to web2py-users
Maybe this thread can be of help too?
I never really got a reply to my original request, but I think that
Massimo's video about components is enough to get me started.

http://groups.google.com/group/web2py/browse_thread/thread/14be20af41a07889/676eae90b8641b76?lnk=gst&q=stefaan.himpe#676eae90b8641b76
Reply all
Reply to author
Forward
0 new messages