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