Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 1601:e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 15 Nov 2015 23:11:27 +0100 |
parents | e2ed8009e66e |
children | 5b24d6bf5d15 |
comparison
equal
deleted
inserted
replaced
1600:8d41cd4da2f6 | 1601:e0a152f2cf6d |
---|---|
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, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE): | 1252 def deferXMLUI(host, xmlui, action_extra=None, 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 action_extra(None, dict): extra action to merge with xmlui | |
1259 mainly used to add meta informations (see actionNew doc) | |
1258 @param security_limit: %(doc_security_limit)s | 1260 @param security_limit: %(doc_security_limit)s |
1259 @return (data): a deferred which fire the data | 1261 @return (data): a deferred which fire the data |
1260 """ | 1262 """ |
1261 assert xmlui.submit_id == '' | 1263 assert xmlui.submit_id == '' |
1262 xmlui_d = defer.Deferred() | 1264 xmlui_d = defer.Deferred() |
1264 def onSubmit(data, profile): | 1266 def onSubmit(data, profile): |
1265 xmlui_d.callback(data) | 1267 xmlui_d.callback(data) |
1266 return {} | 1268 return {} |
1267 | 1269 |
1268 xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True) | 1270 xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True) |
1269 host.actionNew({'xmlui': xmlui.toXml()}, profile=profile) | 1271 action_data = {'xmlui': xmlui.toXml()} |
1272 if action_extra is not None: | |
1273 action_data.update(action_extra) | |
1274 host.actionNew(action_data, profile=profile) | |
1270 return xmlui_d | 1275 return xmlui_d |
1271 | 1276 |
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): | 1277 def deferDialog(host, message, title=u'Please confirm', type_=C.XMLUI_DIALOG_CONFIRM, options=None, |
1278 action_extra=None, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE): | |
1273 """Create a submitable dialog and manage it with a deferred | 1279 """Create a submitable dialog and manage it with a deferred |
1274 | 1280 |
1275 @param message(unicode): message to display | 1281 @param message(unicode): message to display |
1276 @param title(unicode): title of the dialog | 1282 @param title(unicode): title of the dialog |
1277 @param type(unicode): dialog type (C.XMLUI_DIALOG_*) | 1283 @param type(unicode): dialog type (C.XMLUI_DIALOG_*) |
1278 @param options(None, dict): if not None, will be used to update (extend) dialog_opt arguments of XMLUI | 1284 @param options(None, dict): if not None, will be used to update (extend) dialog_opt arguments of XMLUI |
1285 @param action_extra(None, dict): extra action to merge with xmlui | |
1286 mainly used to add meta informations (see actionNew doc) | |
1287 @param security_limit: %(doc_security_limit)s | |
1279 @param profile: %(doc_profile)s | 1288 @param profile: %(doc_profile)s |
1280 @return (dict): Deferred dict | 1289 @return (dict): Deferred dict |
1281 """ | 1290 """ |
1282 assert profile is not None | 1291 assert profile is not None |
1283 dialog_opt = {'type': type_, 'message': message} | 1292 dialog_opt = {'type': type_, 'message': message} |
1284 if options is not None: | 1293 if options is not None: |
1285 dialog_opt.update(options) | 1294 dialog_opt.update(options) |
1286 dialog = XMLUI(C.XMLUI_DIALOG, title=title, dialog_opt=dialog_opt, submit_id='') | 1295 dialog = XMLUI(C.XMLUI_DIALOG, title=title, dialog_opt=dialog_opt, submit_id='') |
1287 return deferXMLUI(host, dialog, security_limit, profile) | 1296 return deferXMLUI(host, dialog, action_extra, security_limit, profile) |
1288 | 1297 |
1289 def deferConfirm(*args, **kwargs): | 1298 def deferConfirm(*args, **kwargs): |
1290 """call deferDialog and return a boolean instead of the whole data dict""" | 1299 """call deferDialog and return a boolean instead of the whole data dict""" |
1291 d = deferDialog(*args, **kwargs) | 1300 d = deferDialog(*args, **kwargs) |
1292 d.addCallback(lambda data: C.bool(data['answer'])) | 1301 d.addCallback(lambda data: C.bool(data['answer'])) |