Skip to content

Commit c1124cb

Browse files
committed
Teach the Form class about <action> elements
An <action> element has - a mandatory title attribute - a mandatory <command> child element - an optional <enable_if> child element title is a translatable text string describing the action <enable_if> is a single expression. When the result of calling eval on the expression is true, the command my be run. If no enable_if node is present, the command default to be enabled all of the time. <command> is the Python code to implement the action. The code is exec()'d in the context of the EditForm class
1 parent 2ac2478 commit c1124cb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Form/form.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# Python imports
2727
#
2828
#---------------------------------------------------------------
29+
from collections import namedtuple
2930
import os
3031
import xml.dom.minidom
3132

@@ -158,9 +159,23 @@ def __load_definitions(self, definition_file):
158159
long_text = _(longname[0].childNodes[0].data)
159160
else:
160161
long_text = attr_text
162+
column_actions = column.getElementsByTagName('action')
163+
actions = []
164+
action = namedtuple('action', ['title', 'command', 'enable_if'])
165+
for act in column_actions:
166+
title = _(act.attributes['title'].value)
167+
commands = act.getElementsByTagName('command')
168+
command = commands[0].childNodes[0].wholeText
169+
enable_if = None
170+
enable_if_elements = act.getElementsByTagName('enable_if')
171+
if enable_if_elements:
172+
# strip both leading and trailing whitespace. This allows clearer formatting in the XML file.
173+
enable_if = enable_if_elements[0].firstChild.wholeText.strip()
174+
actions.append(action(title, command, enable_if))
161175
self.__columns[id][role].append((attr_text,
162176
long_text,
163-
int(size_text)))
177+
int(size_text),
178+
actions))
164179
dom.unlink()
165180

166181
def get_form_ids(self):

0 commit comments

Comments
 (0)