1 #!/usr/bin/env python 2 3 "A very simple example application." 4 5 import WebStack.Generic 6 import XSLForms.Resources 7 import XSLForms.Utils 8 import os 9 10 # Site map imports. 11 12 from WebStack.Resources.ResourceMap import MapResource 13 from WebStack.Resources.Static import DirectoryResource 14 15 # Resource classes. 16 17 class VerySimpleResource(XSLForms.Resources.XSLFormsResource): 18 19 "A very simple resource providing a hierarchy of editable fields." 20 21 resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") 22 encoding = "utf-8" 23 template_resources = { 24 "structure" : ("structure_template.xhtml", "structure_output.xsl") 25 } 26 27 def respond_to_form(self, trans, form): 28 29 """ 30 Respond to a request having the given transaction 'trans' and the given 31 'form' information. 32 """ 33 34 parameters = form.get_parameters() 35 documents = form.get_documents() 36 37 # Ensure the presence of a document. 38 39 if documents.has_key("structure"): 40 structure = documents["structure"] 41 else: 42 structure = form.new_instance("structure") 43 44 # Add and remove elements according to the selectors found. 45 46 selectors = form.get_selectors() 47 XSLForms.Utils.remove_elements(selectors.get("remove2")) 48 XSLForms.Utils.add_elements(selectors.get("add2"), "subitem") 49 XSLForms.Utils.remove_elements(selectors.get("remove")) 50 XSLForms.Utils.add_elements(selectors.get("add"), "item") 51 52 # Start the response. 53 54 trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding)) 55 56 # Ensure that an output stylesheet exists. 57 58 trans_xsl = self.prepare_output("structure") 59 60 # Complete the response. 61 62 self.send_output(trans, [trans_xsl], structure) 63 64 # Site map initialisation. 65 66 def get_site(): 67 68 "Return a simple Web site resource." 69 70 return VerySimpleResource() 71 72 # vim: tabstop=4 expandtab shiftwidth=4