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