On Sat, Mar 16, 2013 at 10:42 PM, Michael Ellis
<michael.f.el...@gmail.com> wrote:
> I've got an application that accepts JSON test reports from remote systems
> and displays them in a SQLFORM grid with the most recent reports first.  The
> controller and view for what the user sees is essentially the following:
>
> CONTROLLER
> def test_report_manage():
>     """ Controller for Reports page """
>     ...
>     form = SQLFORM.grid( ... )
>     return locals()
>
> VIEW
> ...
> {=form}
> ...
>
> The JSON controller is separate from the above.  It merely validates and
> inserts new report records.  The reports arrive at random intervals.  My
> client has asked for the page to automatically update when new reports
> arrive.  What's the cleanest way to go about this, bearing in mind that this
> functionality is mainly intended for demonstration purposes at a trade show?
>

The easiest way is to poll. Something like this:

==== controllers ======

def test_report_manage():
    """ Controller for Reports page """
    ...
    return dict(poll_interval=2000)  # poll at 2 secs intervals
                                                 # if None, don't poll

def test_report_manage_poll():
    form = SQLFORM.grid( ... )
    return form


==== view for test_report_manage controller) =====

<p>
<a href="#" class="btn btn-small btn-success"
            onclick="refresh_grid();return false"><i
                class="icon-refresh icon-white"></i>Refresh</a>
</p>

{{ =LOAD(f='test_report_manage_poll', ajax=False, ajax_trap=True,
target="grid_component") }}

<script>
var refresh_grid = function() {
    web2py_component("{{ =URL(f='test_report_manage_poll')
}}","grid_component");
}

$(document).ready(function() {
    {{ if poll_interval is not None: }}
    setInterval(refresh_grid, {{ =poll_interval }});
    {{ pass }}
});
</script>

Regards
Ricardo

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to