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 "structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl") 21 } 22 transform_resources = { 23 #"types" : ["structure_types.xsl"] 24 "types" : ["structure_multivalue_types.xsl"] 25 } 26 document_resources = { 27 "types" : "structure_types.xml" 28 } 29 30 def respond_to_form(self, trans, form): 31 32 """ 33 Respond to a request having the given transaction 'trans' and the given 34 'form' information. 35 """ 36 37 documents = form.get_documents() 38 39 # Ensure the presence of a document. 40 41 if documents.has_key("structure"): 42 structure = documents["structure"] 43 else: 44 structure = form.new_instance("structure") 45 46 # Add and remove elements according to the selectors found. 47 48 selectors = form.get_selectors() 49 XSLForms.Utils.remove_elements(selectors.get("remove2")) 50 XSLForms.Utils.add_elements(selectors.get("add2"), "subitem") 51 XSLForms.Utils.remove_elements(selectors.get("remove")) 52 XSLForms.Utils.add_elements(selectors.get("add"), "item") 53 54 # Transform, adding enumerations/ranges. 55 56 types_xsl_list = self.prepare_transform("types") 57 types_xml = self.prepare_document("types") 58 structure = self.get_result(types_xsl_list, structure, references={"types" : types_xml}) 59 60 # Start the response. 61 62 trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding)) 63 64 # Ensure that an output stylesheet exists. 65 66 trans_xsl = self.prepare_output("structure") 67 68 # Complete the response. 69 70 self.send_output(trans, [trans_xsl], structure) 71 72 # Site map initialisation. 73 74 def get_site(): 75 76 "Return a simple Web site resource." 77 78 return VerySimpleResource() 79 80 # vim: tabstop=4 expandtab shiftwidth=4