Mercurial > libervia-web
annotate 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 |
rev | line source |
---|---|
918
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 from libervia.server.constants import Const as C |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 from twisted.internet import defer |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from twisted.words.protocols.jabber import jid |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from sat.tools.common import data_objects |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 |
988
d042f194624a
pages (blog_new): added name ("blog_new")
Goffi <goffi@goffi.org>
parents:
918
diff
changeset
|
9 name = u"blog_view" |
918
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 access = C.PAGES_ACCESS_PUBLIC # can be a callable |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 template = u"blog/articles.html" |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 @defer.inlineCallbacks |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 def parse_url(self, request): |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 try: |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 prof_requested = self.nextPath(request) |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 except IndexError: |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 self.pageError(request) |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 template_data = request.template_data |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 target_profile = yield self.host.bridge.profileNameGet(prof_requested) |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 template_data[u'target_profile'] = target_profile |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 target_jid = yield self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', profile_key=target_profile) |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 target_jid = jid.JID(target_jid).userhost() |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 template_data[u'target_jid'] = target_jid |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 @defer.inlineCallbacks |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 def prepare_render(self, request): |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 target_jid = request.template_data[u'target_jid'] |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 blog_data = yield self.host.bridge.mbGet( |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 target_jid, |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 "", |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 10, |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 [], |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 {}, |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 C.SERVICE_PROFILE) |
96a56856d357
pages (blog_new/articles): first concert Libervia page, blog articles:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 request.template_data[u'items'] = data_objects.BlogItems(blog_data) |