"""
Utility method to dump all the fields of a PDFForm
"""

# set this to the name of the script you want to save in container
output_script_name= None

script = "## autogenerated by %s\n"%script
for pdf in container.objectValues('ERP5 PDF Form')[2:3] :
  script+= "form = container['%s']\n"%pdf.id()
  for cell in pdf.getCellNames() :
     script+= 'form.setCellTALES("%s", "%s")\n'%(cell, pdf.getCellTALES(cell).replace('"', '\\"'))
  script += "form.setPageRangeTALES('%s')\n"%pdf.getPageRangeTALES()
  script += "form.setDisplayZerosTALES('%s')\n"%pdf.getDisplayZerosTALES()
  script += "\n\n"

if not output_script_name : 
  return script

container.manage_addProduct['PythonScripts'].manage_addPythonScript(output_script_name) 
container[output_script_name].write(script)

return "%s saved"%output_script_name


# stock of utility functions

for pdf in container.objectValues('ERP5 PDF Form') :
  for cell in pdf.getCellNames() :
     if pdf.getCellTALES(cell) in ( "", None ) : 
       pdf.setCellTALES(cell, 'python:0')
