1.1 --- a/MoinForms.py Sun Dec 02 00:54:15 2012 +0100
1.2 +++ b/MoinForms.py Sun Dec 02 01:40:02 2012 +0100
1.3 @@ -168,12 +168,15 @@
1.4 escattr(page.url(request, querystr))
1.5 ))
1.6
1.7 + # Obtain page text for the form, incorporating subregions and applicable
1.8 + # sections.
1.9 +
1.10 output = getFormOutput(text, fields)
1.11 write(formatText(output, request, fmt, inhibit_p=False))
1.12
1.13 write(fmt.rawHTML('</form>'))
1.14
1.15 -def getFormOutput(text, fields):
1.16 +def getFormOutput(text, fields, path=None):
1.17
1.18 """
1.19 Combine regions found in the given 'text' and then return them as a single
1.20 @@ -192,10 +195,14 @@
1.21 for region in getRegions(text, True):
1.22 format, attributes, body, header, close = getFragmentFromRegion(region)
1.23
1.24 - # Include bare regions as they are.
1.25 + # Adjust any FormField macros to use hierarchical names.
1.26
1.27 if format is None:
1.28 - output.append(region)
1.29 + if path:
1.30 + adjusted_body = adjustFormFields(body, path)
1.31 + output.append(adjusted_body)
1.32 + else:
1.33 + output.append(body)
1.34
1.35 # Include form sections only if fields exist for those sections.
1.36
1.37 @@ -206,26 +213,27 @@
1.38 # Iterate over the section contents ignoring the given indexes.
1.39
1.40 for index, element in enumerate(getSectionElements(section[section_name])):
1.41 -
1.42 - # Adjust FormField macros to use hierarchical names.
1.43 + element_ref = "%s$%s" % (section_name, index)
1.44
1.45 - adjusted_body = adjustFormFields(body, section_name, index)
1.46 - output.append(getFormOutput(adjusted_body, element))
1.47 + # Get the output for the section.
1.48 +
1.49 + output.append(getFormOutput(body, element,
1.50 + path and ("%s/%s" % (path, element_ref)) or element_ref))
1.51
1.52 # Inspect and include other regions.
1.53
1.54 else:
1.55 output.append(header)
1.56 - output.append(getFormOutput(body, section))
1.57 + output.append(getFormOutput(body, section, path))
1.58 output.append(close)
1.59
1.60 return "".join(output)
1.61
1.62 -def adjustFormFields(body, section_name, index):
1.63 +def adjustFormFields(body, path):
1.64
1.65 """
1.66 Return a version of the 'body' with the names in FormField macros updated to
1.67 - incorporate the given 'section_name' and 'index'.
1.68 + incorporate the given 'path'.
1.69 """
1.70
1.71 result = []
1.72 @@ -250,30 +258,30 @@
1.73
1.74 else:
1.75 result.append("<<Form%s(%s)>>" % (type, ",".join(
1.76 - adjustMacroArguments(parseMacroArguments(match), section_name, index)
1.77 + adjustMacroArguments(parseMacroArguments(match), path)
1.78 )))
1.79 state = None
1.80
1.81 return "".join(result)
1.82
1.83 -def adjustMacroArguments(args, section_name, index):
1.84 +def adjustMacroArguments(args, path):
1.85
1.86 """
1.87 Adjust the given 'args' so that the path incorporates the given
1.88 - 'section_name' and 'index', returning a new list containing the revised
1.89 - path and remaining arguments.
1.90 + 'path', returning a new list containing the revised path and remaining
1.91 + arguments.
1.92 """
1.93
1.94 result = []
1.95 - path = None
1.96 + old_path = None
1.97
1.98 for arg in args:
1.99 if arg.startswith("path="):
1.100 - path = arg[5:]
1.101 + old_path = arg[5:]
1.102 else:
1.103 result.append(arg)
1.104
1.105 - qualified = "%s%s$%s" % (path and ("%s/" % path) or "", section_name, index)
1.106 + qualified = old_path and ("%s/%s" % (old_path, path)) or path
1.107 result.append("path=%s" % qualified)
1.108
1.109 return result