Mercurial > libervia-web
annotate src/pages/tickets/view/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 | b92b06f023cb |
children | 1c09f41e2f52 |
rev | line source |
---|---|
967 | 1 #!/usr/bin/env python2.7 |
2 # -*- coding: utf-8 -*- | |
3 | |
4 from libervia.server.constants import Const as C | |
5 from sat.core.i18n import _ | |
6 from twisted.internet import defer | |
7 from sat.tools.common import template_xmlui | |
8 from sat.tools.common import uri | |
9 from sat.tools.common import data_objects | |
10 from sat.core.log import getLogger | |
11 log = getLogger('pages/tickets/view') | |
12 """ticket handling pages""" | |
13 | |
981
97cce8c1e96a
pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents:
975
diff
changeset
|
14 name = u"tickets_view" |
967 | 15 access = C.PAGES_ACCESS_PUBLIC |
16 template = u"ticket/item.html" | |
17 | |
18 | |
19 def parse_url(self, request): | |
20 try: | |
21 item_id = self.nextPath(request) | |
22 except IndexError: | |
23 log.warning(_(u"no ticket id specified")) | |
24 self.pageError(request, C.HTTP_BAD_REQUEST) | |
25 | |
26 data = self.getRData(request) | |
27 data[u'ticket_id'] = item_id | |
28 | |
29 @defer.inlineCallbacks | |
30 def prepare_render(self, request): | |
31 data = self.getRData(request) | |
32 template_data = request.template_data | |
33 service, node, ticket_id = data.get(u'service', u''), data.get(u'node', u''), data[u'ticket_id'] | |
34 profile = self.getProfile(request) | |
35 | |
36 if profile is None: | |
37 profile = C.SERVICE_PROFILE | |
38 | |
39 tickets = yield self.host.bridge.ticketsGet(service.full() if service else u'', node, C.NO_LIMIT, [ticket_id], '', {}, profile) | |
975
75166ac3e0cc
pages (tickets/view): ignore publisher when creating XMLUI
Goffi <goffi@goffi.org>
parents:
967
diff
changeset
|
40 ticket = [template_xmlui.create(self.host, x, ignore=['publisher']) for x in tickets[0]][0] |
967 | 41 template_data[u'item'] = ticket |
42 comments_uri = ticket.widgets['comments_uri'].value | |
43 if comments_uri: | |
44 uri_data = uri.parseXMPPUri(comments_uri) | |
45 template_data['comments_node'] = comments_node = uri_data['node'] | |
46 template_data['comments_service'] = comments_service = uri_data['path'] | |
47 comments = yield self.host.bridge.mbGet(comments_service, | |
48 comments_node, | |
49 C.NO_LIMIT, | |
50 [], | |
51 {}, | |
52 profile) | |
53 | |
54 template_data[u'comments'] = data_objects.BlogItems(comments) | |
55 template_data[u'login_url'] = self.getPageRedirectURL(request) | |
56 | |
57 @defer.inlineCallbacks | |
58 def on_data_post(self, request): | |
59 type_ = self.getPostedData(request, u'type') | |
60 if type_ == u'comment': | |
61 blog_page = self.getPageByName(u'blog') | |
62 yield blog_page.on_data_post(self, request) | |
63 else: | |
64 log.warning(_(u"Unhandled data type: {}").format(type_)) |