comparison src/tools/xml_tools.py @ 1599:e2ed8009e66e

backend, bridge, frontends: actionNew has now a security_limit argument + added some docstring to explain data argument
author Goffi <goffi@goffi.org>
date Sat, 14 Nov 2015 19:21:56 +0100
parents 51dec65ec62c
children e0a152f2cf6d
comparison
equal deleted inserted replaced
1598:b144babc2658 1599:e2ed8009e66e
1247 C.XMLUI_DATA_LVL: level}, 1247 C.XMLUI_DATA_LVL: level},
1248 title=title 1248 title=title
1249 ) 1249 )
1250 return note_xmlui 1250 return note_xmlui
1251 1251
1252 def deferXMLUI(host, xmlui, profile): 1252 def deferXMLUI(host, xmlui, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE):
1253 """Create a deferred linked to XMLUI 1253 """Create a deferred linked to XMLUI
1254 1254
1255 @param xmlui(XMLUI): instance of the XMLUI 1255 @param xmlui(XMLUI): instance of the XMLUI
1256 Must be an XMLUI that you can submit, with submit_id set to '' 1256 Must be an XMLUI that you can submit, with submit_id set to ''
1257 @param profile: %(doc_profile)s 1257 @param profile: %(doc_profile)s
1258 @param security_limit: %(doc_security_limit)s
1258 @return (data): a deferred which fire the data 1259 @return (data): a deferred which fire the data
1259 """ 1260 """
1260 assert xmlui.submit_id == '' 1261 assert xmlui.submit_id == ''
1261 xmlui_d = defer.Deferred() 1262 xmlui_d = defer.Deferred()
1262 1263
1263 def onSubmit(data, profile): 1264 def onSubmit(data, profile):
1264 xmlui_d.callback(data) 1265 xmlui_d.callback(data)
1265 return {} 1266 return {}
1266 1267
1267 xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True) 1268 xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True)
1268 host.actionNew({'xmlui': xmlui.toXml()}, profile) 1269 host.actionNew({'xmlui': xmlui.toXml()}, profile=profile)
1269 return xmlui_d 1270 return xmlui_d
1270 1271
1271 def deferDialog(host, message, title=u'Please confirm', type_=C.XMLUI_DIALOG_CONFIRM, options=None, profile=None): 1272 def deferDialog(host, message, title=u'Please confirm', type_=C.XMLUI_DIALOG_CONFIRM, options=None, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE):
1272 """Create a submitable dialog and manage it with a deferred 1273 """Create a submitable dialog and manage it with a deferred
1273 1274
1274 @param message(unicode): message to display 1275 @param message(unicode): message to display
1275 @param title(unicode): title of the dialog 1276 @param title(unicode): title of the dialog
1276 @param type(unicode): dialog type (C.XMLUI_DIALOG_*) 1277 @param type(unicode): dialog type (C.XMLUI_DIALOG_*)
1281 assert profile is not None 1282 assert profile is not None
1282 dialog_opt = {'type': type_, 'message': message} 1283 dialog_opt = {'type': type_, 'message': message}
1283 if options is not None: 1284 if options is not None:
1284 dialog_opt.update(options) 1285 dialog_opt.update(options)
1285 dialog = XMLUI(C.XMLUI_DIALOG, title=title, dialog_opt=dialog_opt, submit_id='') 1286 dialog = XMLUI(C.XMLUI_DIALOG, title=title, dialog_opt=dialog_opt, submit_id='')
1286 return deferXMLUI(host, dialog, profile) 1287 return deferXMLUI(host, dialog, security_limit, profile)
1287 1288
1288 def deferConfirm(*args, **kwargs): 1289 def deferConfirm(*args, **kwargs):
1289 """call deferDialog and return a boolean instead of the whole data dict""" 1290 """call deferDialog and return a boolean instead of the whole data dict"""
1290 d = deferDialog(*args, **kwargs) 1291 d = deferDialog(*args, **kwargs)
1291 d.addCallback(lambda data: C.bool(data['answer'])) 1292 d.addCallback(lambda data: C.bool(data['answer']))