[gen] Moved action-related stuff from mixins/__init__.py to field/action.py.
This commit is contained in:
parent
5de5372bec
commit
b5d38ad150
2 changed files with 39 additions and 52 deletions
fields
|
@ -15,6 +15,7 @@
|
|||
# Appy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
import os.path
|
||||
from appy.fields import Field
|
||||
from appy.px import Px
|
||||
from appy.shared import utils as sutils
|
||||
|
@ -26,11 +27,10 @@ class Action(Field):
|
|||
|
||||
# PX for viewing the Action button.
|
||||
pxView = pxCell = Px('''
|
||||
<form name="executeAppyAction"
|
||||
var="formId='%s_%s_form' % (zobj.UID(), name);
|
||||
<form var="formId='%s_%s_form' % (zobj.id, name);
|
||||
label=_(field.labelId)"
|
||||
id=":formId" action=":ztool.absolute_url() + '/do'">
|
||||
<input type="hidden" name="action" value="ExecuteAppyAction"/>
|
||||
<input type="hidden" name="action" value="ExecuteAction"/>
|
||||
<input type="hidden" name="objectUid" value=":zobj.id"/>
|
||||
<input type="hidden" name="fieldName" value=":name"/>
|
||||
<input if="field.confirm" type="button" class="button"
|
||||
|
@ -62,8 +62,6 @@ class Action(Field):
|
|||
# message about execution of the action;
|
||||
# * 'file' means that the result is the binary content of a file that
|
||||
# the user will download.
|
||||
# * 'filetmp' is similar to file, but the file is a temp file and Appy
|
||||
# will delete it as soon as it will be served to the browser.
|
||||
# * 'redirect' means that the action will lead to the user being
|
||||
# redirected to some other page.
|
||||
self.result = result
|
||||
|
@ -107,6 +105,38 @@ class Action(Field):
|
|||
return res
|
||||
|
||||
def isShowable(self, obj, layoutType):
|
||||
if layoutType == 'edit': return False
|
||||
else: return Field.isShowable(self, obj, layoutType)
|
||||
if layoutType == 'edit': return
|
||||
return Field.isShowable(self, obj, layoutType)
|
||||
|
||||
def onUiRequest(self, obj, rq):
|
||||
'''This method is called when a user triggers the execution of this
|
||||
action from the user interface.'''
|
||||
# Execute the action (method __call__).
|
||||
actionRes = self(obj.appy())
|
||||
parent = obj.getParentNode()
|
||||
parentAq = getattr(parent, 'aq_base', parent)
|
||||
if not hasattr(parentAq, obj.id):
|
||||
# The action has led to obj's deletion.
|
||||
obj.reindex()
|
||||
# Unwrap action results.
|
||||
successfull, msg = actionRes
|
||||
if not msg:
|
||||
# Use the default i18n messages.
|
||||
suffix = successfull and 'done' or 'ko'
|
||||
msg = obj.translate('action_%s' % suffix)
|
||||
if (self.result == 'computation') or not successfull:
|
||||
obj.say(msg)
|
||||
return obj.goto(obj.getUrl(rq['HTTP_REFERER']))
|
||||
elif self.result == 'file':
|
||||
# msg does not contain a message, but a file instance.
|
||||
response = rq.RESPONSE
|
||||
response.setHeader('Content-Type', sutils.getMimeType(msg.name))
|
||||
response.setHeader('Content-Disposition', 'inline;filename="%s"' %\
|
||||
os.path.basename(msg.name))
|
||||
response.write(msg.read())
|
||||
msg.close()
|
||||
elif self.result == 'redirect':
|
||||
# msg does not contain a message, but the URL where to redirect
|
||||
# the user.
|
||||
return obj.goto(msg)
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue