# HG changeset patch # User Paul Boddie # Date 1354408802 -3600 # Node ID 3ceaae65f98234ddd78db437e7036b7874ecf9c1 # Parent 8fe065e89206cd40abac19c8e0ac46e931f101e2 Changed the form output generation to only adjust macro arguments once per macro by maintaining the path state in getFormOutput. diff -r 8fe065e89206 -r 3ceaae65f982 MoinForms.py --- a/MoinForms.py Sun Dec 02 00:54:15 2012 +0100 +++ b/MoinForms.py Sun Dec 02 01:40:02 2012 +0100 @@ -168,12 +168,15 @@ escattr(page.url(request, querystr)) )) + # Obtain page text for the form, incorporating subregions and applicable + # sections. + output = getFormOutput(text, fields) write(formatText(output, request, fmt, inhibit_p=False)) write(fmt.rawHTML('')) -def getFormOutput(text, fields): +def getFormOutput(text, fields, path=None): """ Combine regions found in the given 'text' and then return them as a single @@ -192,10 +195,14 @@ for region in getRegions(text, True): format, attributes, body, header, close = getFragmentFromRegion(region) - # Include bare regions as they are. + # Adjust any FormField macros to use hierarchical names. if format is None: - output.append(region) + if path: + adjusted_body = adjustFormFields(body, path) + output.append(adjusted_body) + else: + output.append(body) # Include form sections only if fields exist for those sections. @@ -206,26 +213,27 @@ # Iterate over the section contents ignoring the given indexes. for index, element in enumerate(getSectionElements(section[section_name])): - - # Adjust FormField macros to use hierarchical names. + element_ref = "%s$%s" % (section_name, index) - adjusted_body = adjustFormFields(body, section_name, index) - output.append(getFormOutput(adjusted_body, element)) + # Get the output for the section. + + output.append(getFormOutput(body, element, + path and ("%s/%s" % (path, element_ref)) or element_ref)) # Inspect and include other regions. else: output.append(header) - output.append(getFormOutput(body, section)) + output.append(getFormOutput(body, section, path)) output.append(close) return "".join(output) -def adjustFormFields(body, section_name, index): +def adjustFormFields(body, path): """ Return a version of the 'body' with the names in FormField macros updated to - incorporate the given 'section_name' and 'index'. + incorporate the given 'path'. """ result = [] @@ -250,30 +258,30 @@ else: result.append("<>" % (type, ",".join( - adjustMacroArguments(parseMacroArguments(match), section_name, index) + adjustMacroArguments(parseMacroArguments(match), path) ))) state = None return "".join(result) -def adjustMacroArguments(args, section_name, index): +def adjustMacroArguments(args, path): """ Adjust the given 'args' so that the path incorporates the given - 'section_name' and 'index', returning a new list containing the revised - path and remaining arguments. + 'path', returning a new list containing the revised path and remaining + arguments. """ result = [] - path = None + old_path = None for arg in args: if arg.startswith("path="): - path = arg[5:] + old_path = arg[5:] else: result.append(arg) - qualified = "%s%s$%s" % (path and ("%s/" % path) or "", section_name, index) + qualified = old_path and ("%s/%s" % (old_path, path)) or path result.append("path=%s" % qualified) return result