# HG changeset patch # User paulb # Date 1121639719 0 # Node ID 7e924f759ce24a913cb3ef848f12c77442e670d3 # Parent 4deb57f556b05f71378c39eba1c0302cbed906de [project @ 2005-07-17 22:35:16 by paulb] Added a very simple example similar to that described in the documentation. diff -r 4deb57f556b0 -r 7e924f759ce2 examples/Common/VerySimple/Resources/structure_template.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/VerySimple/Resources/structure_template.xhtml Sun Jul 17 22:35:19 2005 +0000 @@ -0,0 +1,42 @@ + + + + + Example + + +
+ + + +
+

+ + Some item: + + +

+

+ Itself containing more items: +

+

+ + Sub-item: + + +

+

+ +

+
+

+ +

+ + + +
+ + diff -r 4deb57f556b0 -r 7e924f759ce2 examples/Common/VerySimple/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/VerySimple/__init__.py Sun Jul 17 22:35:19 2005 +0000 @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +"A very simple example application." + +import WebStack.Generic +import XSLForms.Resources +import XSLForms.Utils +import os + +# Site map imports. + +from WebStack.Resources.ResourceMap import MapResource +from WebStack.Resources.Static import DirectoryResource + +# Resource classes. + +class VerySimpleResource(XSLForms.Resources.XSLFormsResource): + + "A very simple resource providing a hierarchy of editable fields." + + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") + encoding = "utf-8" + template_resources = { + "structure" : ("structure_template.xhtml", "structure_output.xsl") + } + + def respond_to_form(self, trans, form): + + """ + Respond to a request having the given transaction 'trans' and the given + 'form' information. + """ + + parameters = form.get_parameters() + documents = form.get_documents() + + # Ensure the presence of a document. + + if documents.has_key("structure"): + structure = documents["structure"] + else: + structure = form.new_instance("structure") + + # Add and remove elements according to the selectors found. + + selectors = form.get_selectors() + XSLForms.Utils.remove_elements(selectors.get("remove2")) + XSLForms.Utils.add_elements(selectors.get("add2"), "subitem") + XSLForms.Utils.remove_elements(selectors.get("remove")) + XSLForms.Utils.add_elements(selectors.get("add"), "item") + + # Start the response. + + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding)) + + # Ensure that an output stylesheet exists. + + trans_xsl = self.prepare_output("structure") + + # Complete the response. + + self.send_output(trans, [trans_xsl], structure) + +# Site map initialisation. + +def get_site(): + + "Return a simple Web site resource." + + return VerySimpleResource() + +# vim: tabstop=4 expandtab shiftwidth=4