Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Arguments(object):
- """Selector-specific arguments.
- The parser used during construction limits parsing to only the attributes
- required for the represented use case, and the attributes necessary to
- derive those attributes.
- """
- class Parser(object):
- # Parse args control
- def fields(args, temps): # link_ctrl, field_ctrls
- if temps.type_multiple: return
- ctrls = [getByPath(args.form, path) for path in temps.args[3:]]
- if temps.type_link:
- args.link_ctrl, args.field_ctrls = ctrls[0], ctrls[1:]
- else:
- args.field_ctrls = ctrls
- def components(args, temps):
- if not temps.type_multiple: return
- args.components = []
- for path in temps.args[3:]:
- ctrl = getByPath(args.form, path)
- q_ctrl = getByPath(ctrl.Parent, ctrl.HiddenValue.split(LIST_SEP, 3)[2])
- args.components.append( (q_ctrl.HiddenValue.split(LIST_SEP, 1)[0], ctrl) )
- # Parse query control
- def delimiters(args, temps):
- args.prefix, args.delimiter = args.query_ctrl.HiddenValue.split(LIST_SEP, 2)[:2]
- def substitutions(args, temps):
- args.substitutions = safeSplit(args.query_ctrl.HiddenValue, LIST_SEP)[2:]
- def query(args, temps):
- args.query = args.query_ctrl.Tag
- # Parse link control
- def links(args, temps): #link_button, link_paths; @depends(fields)
- if not temps.type_link: return
- args.link_paths = safeSplit(args.link_ctrl.HiddenValue, LIST_SEP)
- if args.select_type == SelectType.LINKING:
- args.link_button = getByPath(args.form, args.link_paths[0])
- args.link_paths = args.link_paths[1:]
- def link_ctrls(args, temps): #@depends(links)
- if not temps.type_link: return
- args.link_ctrls = [getByPath(args.form, path) for path in args.link_paths]
- def link_inputs(args, temps): #@depends(fields)
- if not temps.type_link: return
- args.link_inputs = [getValue(getByPath(args.form, path)) for path
- in safeSplit(args.link_ctrl.Tag, LIST_SEP)]
- # Parse input control
- def input(args, temps):
- args.input = args.input_ctrl.Text
- def inputs(args, temps): #@depends(input, delimiters, fields)
- if temps.type_multiple: return
- args.inputs = safeSplit(args.input[len(args.prefix):], args.delimiter,
- len(args.field_ctrls) - 1, empty_list=False)
- # (Not actually parsing)
- def form_ops(args, temps):
- # ThisComponent = XSCRIPTCONTEXT.getDocument()
- args.form_ops = (XSCRIPTCONTEXT.getDocument().CurrentController
- .getFormController(args.form).FormOperations)
- SELECT = [fields, links, input, delimiters, inputs, components, form_ops] # Depended: delimiters
- QUERY = [substitutions, query]
- LINK_INPUTS = SELECT + [link_inputs]
- VISIBLE = [components, fields, links, link_ctrls] # Depended: fields, links
- REFRESH = [fields, links, delimiters]
- def __init__(self, form, args_ctrl, parser=Parser.SELECT):
- self.form = form
- self.args_ctrl = args_ctrl
- args, self.child_paths = extractArgs(args_ctrl)
- self.select_type = SelectType.types[args[0]]
- self.input_ctrl, self.query_ctrl = [getByPath(form, path) for path in args[1:3]]
- temps = object()
- temps.args = args
- temps.type_link = self.select_type in (SelectType.LINKED, SelectType.LINKING)
- temps.type_multiple = (self.select_type == SelectType.MULTIPLE)
- for func in parser:
- func(self, temps)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement