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