[gen] Executng actions from list of tied objects (ref field): bugfix.

This commit is contained in:
Gaetan Delannay 2015-01-07 18:20:48 +01:00
parent 746a6cd52d
commit 90657e0faf
2 changed files with 8 additions and 9 deletions

View file

@ -33,10 +33,8 @@ class Action(Field):
buttonWidth=ztool.getButtonWidth(label); buttonWidth=ztool.getButtonWidth(label);
smallButtons=smallButtons|False; smallButtons=smallButtons|False;
css=smallButtons and 'buttonSmall button' or 'button'" css=smallButtons and 'buttonSmall button' or 'button'"
id=":formId" action=":ztool.absolute_url() + '/do'" id=":formId" action=":zobj.absolute_url() + '/onExecuteAction'"
style="display:inline"> style="display:inline">
<input type="hidden" name="action" value="ExecuteAction"/>
<input type="hidden" name="objectUid" value=":zobj.id"/>
<input type="hidden" name="fieldName" value=":name"/> <input type="hidden" name="fieldName" value=":name"/>
<input type="hidden" name="comment" value=""/> <input type="hidden" name="comment" value=""/>
<input if="field.confirm" type="button" class=":css" title=":descr" <input if="field.confirm" type="button" class=":css" title=":descr"
@ -133,24 +131,24 @@ class Action(Field):
def onUiRequest(self, obj, rq): def onUiRequest(self, obj, rq):
'''This method is called when a user triggers the execution of this '''This method is called when a user triggers the execution of this
action from the user interface.''' action from the user interface.'''
# Execute the action (method __call__). # Execute the action (method __call__)
actionRes = self(obj.appy()) actionRes = self(obj.appy())
parent = obj.getParentNode() parent = obj.getParentNode()
parentAq = getattr(parent, 'aq_base', parent) parentAq = getattr(parent, 'aq_base', parent)
if not hasattr(parentAq, obj.id): if not hasattr(parentAq, obj.id):
# The action has led to obj's deletion. # The action has led to obj's deletion
obj.reindex() obj.reindex()
# Unwrap action results. # Unwrap action results
successfull, msg = actionRes successfull, msg = actionRes
if not msg: if not msg:
# Use the default i18n messages. # Use the default i18n messages
suffix = successfull and 'done' or 'ko' suffix = successfull and 'done' or 'ko'
msg = obj.translate('action_%s' % suffix) msg = obj.translate('action_%s' % suffix)
if (self.result == 'computation') or not successfull: if (self.result == 'computation') or not successfull:
obj.say(msg) obj.say(msg)
return obj.goto(obj.getUrl(rq['HTTP_REFERER'])) return obj.goto(obj.getUrl(rq['HTTP_REFERER']))
elif self.result == 'file': elif self.result == 'file':
# msg does not contain a message, but a file instance. # msg does not contain a message, but a file instance
response = rq.RESPONSE response = rq.RESPONSE
response.setHeader('Content-Type', sutils.getMimeType(msg.name)) response.setHeader('Content-Type', sutils.getMimeType(msg.name))
response.setHeader('Content-Disposition', 'inline;filename="%s"' %\ response.setHeader('Content-Disposition', 'inline;filename="%s"' %\

View file

@ -132,7 +132,8 @@ class Ref(Field):
<!-- Fields (actions) defined with layout "buttons" --> <!-- Fields (actions) defined with layout "buttons" -->
<x if="not inPopup" <x if="not inPopup"
var2="fields=tied.o.getAppyTypes('buttons', 'main', type='Action'); var2="fields=tied.o.getAppyTypes('buttons', 'main', type='Action');
layoutType='view'"> layoutType='view';
zobj=tied.o">
<!-- Call pxView and not pxRender to avoid having a table --> <!-- Call pxView and not pxRender to avoid having a table -->
<x for="field in fields" <x for="field in fields"
var2="name=field.name; smallButtons=True">:field.pxView</x> var2="name=field.name; smallButtons=True">:field.pxView</x>