1 #!/usr/bin/env python 2 3 "An example of recursive templates." 4 5 import WebStack.Generic 6 from XSLForms.Resources.WebResources import \ 7 XSLFormsResource, input, output, resources, prepare_resources as xslforms_prepare_resources 8 9 # Site map imports. 10 11 from WebStack.Resources.Selectors import EncodingSelector 12 13 # Configuration settings. 14 15 encoding = "utf-8" 16 17 # Resource classes. 18 19 class RecursiveResource(XSLFormsResource): 20 21 "A resource providing a recursive hierarchy of editable fields." 22 23 resource_dir = resources(__file__) 24 template_resources = { 25 "recursive" : output("recursive_template.xhtml") 26 } 27 init_resources = { 28 "recursive" : input("recursive_template.xhtml") 29 } 30 31 def select_activity(self, trans, form): 32 form.set_activity("recursive") 33 34 def respond_to_input(self, trans, form): 35 36 # Add and remove elements according to the selectors found. 37 38 selectors = form.get_selectors() 39 self.remove_elements(selectors.get("remove")) 40 self.add_elements(selectors.get("add-list"), "list") 41 self.add_elements(selectors.get("add-item"), "item") 42 43 # Site map initialisation. 44 45 def get_site(): 46 47 "Return a simple Web site resource." 48 49 # Get the main resource and the directory used by the application. 50 51 resource = RecursiveResource() 52 return EncodingSelector(resource, encoding) 53 54 # Resource preparation ahead of time - useful for making installations. 55 56 def prepare_resources(): 57 for cls in [RecursiveResource]: 58 XSLForms.Resources.WebResources.prepare_resources(cls) 59 60 # vim: tabstop=4 expandtab shiftwidth=4