Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def export(*names):
- """A decorator to export the specified local variables.
- Before returning, set self._locals = locals()
- self._locals will be deleted by the decorator.
- """
- def wrapper(func):
- def export(self, *args, **kwargs):
- func(self, *args, **kwargs)
- for name in names:
- if name in self._locals:
- self.__dict__[name] = self._locals[name]
- del self._locals
- return export
- return wrapper
- class Arguments(object):
- """Selector-specific arguments.
- The mode used during construction limits parsing to only the attributes
- required by that mode.
- """
- class Mode(object):
- SELECT = 0
- QUERY = 1
- LINK_INPUTS = 2
- VISIBLE = 3
- REFRESH = 4
- @export("form", "args_ctrl",
- "select_type", "input_ctrl", "query_ctrl", "link_ctrl",
- "field_ctrls", "components", "child_paths",
- "prefix", "delimiter", "substitutions", "query",
- "link_button", "link_paths", "link_inputs", "link_ctrls",
- "input", "inputs", "form_ops")
- def __init__(self, form, args_ctrl, mode=0): #Arguments.Mode.SELECT
- args, child_paths = extractArgs(args_ctrl)
- select_type = SelectType.types[args[0]]
- input_ctrl, query_ctrl = [getByPath(form, path) for path in args[1:3]]
- if mode == Arguments.Mode.QUERY:
- substitutions = safeSplit(query_ctrl.HiddenValue, LIST_SEP)[2:]
- query = query_ctrl.Tag
- else:
- input = input_ctrl.Text
- if select_type == SelectType.MULTIPLE:
- if mode != Arguments.Mode.REFRESH:
- components = []
- for path in args[3:]:
- ctrl = getByPath(form, path)
- q_ctrl = getByPath(ctrl.Parent, ctrl.HiddenValue.split(LIST_SEP, 3)[2])
- components.append( (q_ctrl.HiddenValue.split(LIST_SEP, 1)[0], ctrl) )
- else:
- ctrls = [getByPath(form, path) for path in args[3:]]
- if select_type in (SelectType.LINKED, SelectType.LINKING):
- link_ctrl, field_ctrls = ctrls[0], ctrls[1:]
- link_paths = safeSplit(link_ctrl.HiddenValue, LIST_SEP)
- if select_type == SelectType.LINKING:
- link_button = getByPath(form, link_paths[0])
- link_paths = link_paths[1:]
- if mode == Arguments.Mode.VISIBLE:
- link_ctrls = [getByPath(form, path) for path in link_paths]
- else:
- field_ctrls = ctrls
- if mode != Arguments.Mode.VISIBLE:
- prefix, delimiter = query_ctrl.HiddenValue.split(LIST_SEP, 2)[:2]
- if mode != Arguments.Mode.REFRESH:
- inputs = safeSplit(input[len(prefix):], delimiter,
- len(field_ctrls) - 1, empty_list=False)
- # ThisComponent = XSCRIPTCONTEXT.getDocument()
- form_ops = (XSCRIPTCONTEXT.getDocument().CurrentController
- .getFormController(form).FormOperations)
- if mode == Arguments.Mode.LINK_INPUTS:
- link_inputs = [getValue(getByPath(form, path)) for path in safeSplit(link_ctrl.Tag, LIST_SEP)]
- self._locals = locals()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement