Mercurial > libervia-web
view src/pages/tickets/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 | 1d1a6c91961f |
children | 296bda6b7ed0 |
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 sat.tools.common import template_xmlui from sat.core.log import getLogger log = getLogger('pages/ticket') """ticket handling pages""" name = u'tickets_new' access = C.PAGES_ACCESS_PROFILE template = u"ticket/create.html" @defer.inlineCallbacks def prepare_render(self, request): data = self.getRData(request) template_data = request.template_data service, node = data.get(u'service', u''), data.get(u'node', u'') profile = self.getProfile(request) schema = yield self.host.bridge.ticketsSchemaGet(service.full(), node, profile) data['schema'] = schema # following fields are handled in backend ignore = ('reporter', 'reporter_jid', 'reporter_email', 'created', 'updated', 'comments_uri', 'status', 'milestone', 'priority') xmlui_obj = template_xmlui.create(self.host, schema, ignore=ignore) try: # small trick to get a one line text input instead of the big textarea xmlui_obj.widgets[u'labels'].type = u'string' except KeyError: pass template_data[u'new_ticket_xmlui'] = xmlui_obj @defer.inlineCallbacks def on_data_post(self, request): data = self.getRData(request) service = data['service'] node = data['node'] posted_data = self.getAllPostedData(request) if not posted_data['title'] or not posted_data['body']: self.pageError(request, C.HTTP_BAD_REQUEST) try: posted_data['labels'] = [l.strip() for l in posted_data['labels'][0].split(',')] except (KeyError, IndexError): pass profile = self.getProfile(request) yield self.host.bridge.ticketSet(service.full(), node, posted_data, u'', u'', {}, profile) # we don't want to redirect to creation page on success, but to tickets list data['post_redirect_page'] = (self.getPageByName(u'tickets_list'), service.full(), node or u'@')