1 #!/usr/bin/env python 2 3 "An example of recursive templates." 4 5 import WebStack.Generic 6 import XSLForms.Resources.WebResources 7 import XSLForms.Utils 8 import os 9 10 # Resource classes. 11 12 class RecursiveResource(XSLForms.Resources.WebResources.XSLFormsResource): 13 14 "A resource providing a recursive hierarchy of editable fields." 15 16 resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") 17 encoding = "utf-8" 18 template_resources = { 19 "recursive" : ("recursive_template.xhtml", "recursive_output.xsl") 20 } 21 init_resources = { 22 "recursive" : ("recursive_template.xhtml", "recursive_input.xsl") 23 } 24 25 def respond_to_form(self, trans, form): 26 27 """ 28 Respond to a request having the given transaction 'trans' and the given 29 'form' information. 30 """ 31 32 parameters = form.get_parameters() 33 documents = form.get_documents() 34 35 # Ensure the presence of a document. 36 37 if documents.has_key("recursive"): 38 recursive = documents["recursive"] 39 else: 40 recursive = form.new_instance("recursive") 41 42 # Add and remove elements according to the selectors found. 43 44 selectors = form.get_selectors() 45 XSLForms.Utils.remove_elements(selectors.get("remove")) 46 XSLForms.Utils.add_elements(selectors.get("add-list"), "list") 47 XSLForms.Utils.add_elements(selectors.get("add-item"), "item") 48 49 # Initialise the document, adding enumerations/ranges. 50 51 init_xsl = self.prepare_initialiser("recursive") 52 recursive = self.get_result([init_xsl], recursive) 53 #print recursive.toString("iso-8859-1") 54 55 # Start the response. 56 57 trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding)) 58 59 # Ensure that an output stylesheet exists. 60 61 trans_xsl = self.prepare_output("recursive") 62 stylesheet_parameters = {} 63 64 # Complete the response. 65 66 self.send_output(trans, [trans_xsl], recursive, stylesheet_parameters) 67 68 # Site map initialisation. 69 70 def get_site(): 71 72 "Return a simple Web site resource." 73 74 # Get the main resource and the directory used by the application. 75 76 return RecursiveResource() 77 78 # Resource preparation ahead of time - useful for making installations. 79 80 def prepare_resources(): 81 for cls in [RecursiveResource]: 82 XSLForms.Resources.WebResources.prepare_resources(cls) 83 84 # vim: tabstop=4 expandtab shiftwidth=4