MoinForms

Change of MoinForms.py

4:115c012b287e
MoinForms.py
     1.1 --- a/MoinForms.py	Sat Dec 01 23:54:16 2012 +0100
     1.2 +++ b/MoinForms.py	Sun Dec 02 00:40:22 2012 +0100
     1.3 @@ -13,7 +13,7 @@
     1.4  
     1.5  __version__ = "0.1"
     1.6  
     1.7 -form_field_regexp_str = r"<<FormField\((.*?)\)>>"
     1.8 +form_field_regexp_str = r"<<Form(Field|Message)\((.*?)\)>>"
     1.9  form_field_regexp = re.compile(form_field_regexp_str, re.DOTALL)
    1.10  
    1.11  # Common action functionality.
    1.12 @@ -41,9 +41,13 @@
    1.13          # Modify, serialise and show the form.
    1.14  
    1.15          self.modifyFields(fields)
    1.16 +        self.validateFields(fields)
    1.17          self.serialiseFields(fields, form)
    1.18          do_show(self.pagename, self.request)
    1.19  
    1.20 +    def validateFields(self, fields):
    1.21 +        pass
    1.22 +
    1.23      def serialiseFields(self, fields, form, path=None):
    1.24  
    1.25          """
    1.26 @@ -201,17 +205,30 @@
    1.27      """
    1.28  
    1.29      result = []
    1.30 -    in_macro = False
    1.31 +    state = None
    1.32 +    type = None
    1.33  
    1.34      for match in form_field_regexp.split(body):
    1.35 -        if not in_macro:
    1.36 +
    1.37 +        # Reproduce normal text as is.
    1.38 +
    1.39 +        if not state:
    1.40              result.append(match)
    1.41 +            state = "TYPE"
    1.42 +
    1.43 +        # Capture the macro type.
    1.44 +
    1.45 +        elif state == "TYPE":
    1.46 +            type = match
    1.47 +            state = "ARGS"
    1.48 +
    1.49 +        # Substitute the macro and modified arguments.
    1.50 +
    1.51          else:
    1.52 -            result.append("<<FormField(%s)>>" % ",".join(
    1.53 +            result.append("<<Form%s(%s)>>" % (type, ",".join(
    1.54                  adjustMacroArguments(parseMacroArguments(match), section_name, index)
    1.55 -                ))
    1.56 -
    1.57 -        in_macro = not in_macro
    1.58 +                )))
    1.59 +            state = None
    1.60  
    1.61      return "".join(result)
    1.62  
    1.63 @@ -299,6 +316,13 @@
    1.64      return fields
    1.65  
    1.66  def getPathDetails(path):
    1.67 +
    1.68 +    """
    1.69 +    Return the given 'path' as a list of (name, index) tuples providing details
    1.70 +    of section instances, with any specific field appearing as the last element
    1.71 +    and having the form (name, None).
    1.72 +    """
    1.73 +
    1.74      parts = []
    1.75  
    1.76      for part in path.split("/"):