Mercurial > libervia-web
changeset 318:c12c9a1acf2f
server_side: added support for paramsRegisterApp to define frontend's specific parameters like "Enable unibox"
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 03 Jan 2014 14:19:01 +0100 |
parents | bbadd490e63c |
children | 462a0a8894e3 |
files | libervia.py libervia.tac |
diffstat | 2 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia.py Fri Jan 03 14:14:34 2014 +0100 +++ b/libervia.py Fri Jan 03 14:19:01 2014 +0100 @@ -110,7 +110,7 @@ class RegisterCall(LiberviaJsonProxy): def __init__(self): LiberviaJsonProxy.__init__(self, "/register_api", - ["isRegistered", "isConnected", "connect"]) + ["isRegistered", "isConnected", "connect", "registerParams"]) class BridgeCall(LiberviaJsonProxy): @@ -180,6 +180,7 @@ RootPanel().add(self.panel) DOM.addEventPreview(self) self._register = RegisterCall() + self._register.call('registerParams', None) self._register.call('isRegistered', self._isRegisteredCB) self.initialised = False self.init_cache = [] # used to cache events until initialisation is done @@ -348,7 +349,6 @@ # this would eventually set the browser saved password Timer(5, lambda: self._register_box._form.login_pass_box.setFocus(True)) - def _actionCb(self, data): if not data: # action was a one shot, nothing to do
--- a/libervia.tac Fri Jan 03 14:14:34 2014 +0100 +++ b/libervia.tac Fri Jan 03 14:19:01 2014 +0100 @@ -42,6 +42,7 @@ from zope.interface import Interface, Attribute, implements from xml.dom import minidom from constants import Const +from sat.core.i18n import _, D_ class ISATSession(Interface): @@ -441,7 +442,7 @@ def jsonrpc_getParamsUI(self): """Return the parameters XML for profile""" profile = ISATSession(self.session).profile - d = self.asyncBridgeCall("getParams", Const.SECURITY_LIMIT, profile) + d = self.asyncBridgeCall("getParams", Const.SECURITY_LIMIT, Const.APP_NAME, profile) def setAuthorizedParams(d): if self.authorized_params is None: @@ -530,13 +531,14 @@ Render method with some hacks: - if login is requested, try to login with form data - except login, every method is jsonrpc - - user doesn't need to be authentified for isRegistered, but must be for all other methods + - user doesn't need to be authentified for isRegistered or registerParams, but must be for all other methods """ if request.postpath==['login']: return self.login(request) _session = request.getSession() parsed = jsonrpclib.loads(request.content.read()) - if parsed.get("method")!="isRegistered": + method = parsed.get("method") + if method != "isRegistered" and method != "registerParams": #if we don't call login or isRegistered, we need to be identified profile = ISATSession(_session).profile if not profile: @@ -718,6 +720,25 @@ profile = ISATSession(_session).profile return bool(profile) + def jsonrpc_registerParams(self): + """Register the frontend specific parameters""" + params = """ + <params> + <individual> + <category name="%(category_name)s" label="%(category_label)s"> + <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" security="0"/> + </category> + </individual> + </params> + """ % { + 'category_name': Const.ENABLE_UNIBOX_KEY, + 'category_label': _(Const.ENABLE_UNIBOX_KEY), + 'param_name': Const.ENABLE_UNIBOX_PARAM, + 'param_label': _(Const.ENABLE_UNIBOX_PARAM) + } + + self.sat_host.bridge.paramsRegisterApp(params, Const.SECURITY_LIMIT, Const.APP_NAME) + class SignalHandler(jsonrpc.JSONRPC): @@ -978,7 +999,6 @@ def stop(self): reactor.stop() - registerAdapter(SATSession, server.Session, ISATSession) application = service.Application(Const.APP_NAME) service = Libervia()