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 # Resource classes. 11 12 class VerySimpleResource(XSLForms.Resources.XSLFormsResource): 13 14 "A very simple resource providing a 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 "structure" : ("structure_template.xhtml", "structure_output.xsl") 20 } 21 transform_resources = { 22 "types" : ["structure_types.xsl"] 23 } 24 document_resources = { 25 "types" : "structure_types.xml" 26 } 27 28 def respond_to_form(self, trans, form): 29 30 """ 31 Respond to a request having the given transaction 'trans' and the given 32 'form' information. 33 """ 34 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 # Transform, adding enumerations/ranges. 53 54 types_xsl_list = self.prepare_transform("types") 55 types_xml = self.prepare_document("types") 56 structure = self.get_result(types_xsl_list, structure, references={"types" : types_xml}) 57 58 # Start the response. 59 60 trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding)) 61 62 # Ensure that an output stylesheet exists. 63 64 trans_xsl = self.prepare_output("structure") 65 66 # Complete the response. 67 68 self.send_output(trans, [trans_xsl], structure) 69 70 # Site map initialisation. 71 72 def get_site(): 73 74 "Return a simple Web site resource." 75 76 return VerySimpleResource() 77 78 # vim: tabstop=4 expandtab shiftwidth=4