From f055ec17544070848c07b7bb42adcc592c1d3793 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 5 Dec 2014 11:55:25 +0100 Subject: [PATCH] [gen] Bugfix: For showing a field on layout buttons, the buttons layout must explicitly be returned by the show method. [gen] Action.py: added param 'icon' allowing to specify a specific icon. --- fields/__init__.py | 4 +++- fields/action.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fields/__init__.py b/fields/__init__.py index 2dab81b..880ec72 100644 --- a/fields/__init__.py +++ b/fields/__init__.py @@ -353,7 +353,9 @@ class Field: return elif res in ('view', 'edit', 'result', 'buttons'): return res == layoutType - return bool(res) + # For showing a field on layout "buttons", the "buttons" layout must + # explicitly be returned by the show method. + if layoutType != 'buttons': return bool(res) def isClientVisible(self, obj): '''This method returns True if this field is visible according to diff --git a/fields/action.py b/fields/action.py index 593d579..c3534c6 100644 --- a/fields/action.py +++ b/fields/action.py @@ -25,7 +25,7 @@ class Action(Field): '''An action is a Python method that can be triggered by the user on a given gen-class. An action is rendered as a button.''' - # PX for viewing the Action button. + # PX for viewing the Action button pxView = pxCell = Px('''
+ style=":'%s; %s' % (url(field.icon, bg=True), buttonWidth)"/>
''') - # It is not possible to edit an action, not to search it. + # It is not possible to edit an action, not to search it pxEdit = pxSearch = '' def __init__(self, validator=None, multiplicity=(1,1), default=None, @@ -59,7 +59,7 @@ class Action(Field): width=None, height=None, maxChars=None, colspan=1, action=None, result='computation', confirm=False, master=None, masterValue=None, focus=False, historized=False, mapping=None, - label=None): + label=None, icon=None): # Can be a single method or a list/tuple of methods self.action = action # For the 'result' param: @@ -74,13 +74,15 @@ class Action(Field): # If following field "confirm" is True, a popup will ask the user if # she is really sure about triggering this action. self.confirm = confirm + # If no p_icon is specified, "action.png" will be used + self.icon = icon or 'action' Field.__init__(self, None, (0,1), default, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, None, None, None, None, False) self.validable = False - self.renderLabel = False # Label is rendered directly within the button. + self.renderLabel = False # Label is rendered directly within the button def getDefaultLayouts(self): return {'view': 'l-f', 'edit': 'lrv-f'}