Mercurial > libervia-web
view src/pages/blog_new/page_meta.py @ 995:f88325b56a6a
server: dynamic pages first draft:
/!\ new dependency: autobahn
This patch introduce server part of dynamic pages.
Dynamic pages use websockets to establish constant connection with a Libervia page, allowing to receive real time data or update it.
The feature is activated by specifying "dynamic = true" in the page.
Once activated, page can implement "on_data" method which will be called when data are sent by the page.
To send data the other way, the page can use request.sendData.
The new "registerSignal" method allows to use an "on_signal" method to be called each time given signal is received, with automatic (and optional) filtering on profile.
New renderPartial and renderAndUpdate method allow to append new HTML elements to the dynamic page.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 03 Jan 2018 01:10:12 +0100 |
parents | d042f194624a |
children | fc1c913cc9d1 |
line wrap: on
line source
#!/usr/bin/env python2.7 # -*- coding: utf-8 -*- from libervia.server.constants import Const as C from twisted.internet import defer from twisted.words.protocols.jabber import jid from sat.tools.common import data_objects name = u"blog_view" access = C.PAGES_ACCESS_PUBLIC # can be a callable template = u"blog/articles.html" @defer.inlineCallbacks def parse_url(self, request): try: prof_requested = self.nextPath(request) except IndexError: self.pageError(request) template_data = request.template_data target_profile = yield self.host.bridge.profileNameGet(prof_requested) template_data[u'target_profile'] = target_profile target_jid = yield self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', profile_key=target_profile) target_jid = jid.JID(target_jid).userhost() template_data[u'target_jid'] = target_jid @defer.inlineCallbacks def prepare_render(self, request): target_jid = request.template_data[u'target_jid'] blog_data = yield self.host.bridge.mbGet( target_jid, "", 10, [], {}, C.SERVICE_PROFILE) request.template_data[u'items'] = data_objects.BlogItems(blog_data)