1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/VerySimple/__init__.py Sun Jul 17 22:35:19 2005 +0000
1.3 @@ -0,0 +1,72 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"A very simple example application."
1.7 +
1.8 +import WebStack.Generic
1.9 +import XSLForms.Resources
1.10 +import XSLForms.Utils
1.11 +import os
1.12 +
1.13 +# Site map imports.
1.14 +
1.15 +from WebStack.Resources.ResourceMap import MapResource
1.16 +from WebStack.Resources.Static import DirectoryResource
1.17 +
1.18 +# Resource classes.
1.19 +
1.20 +class VerySimpleResource(XSLForms.Resources.XSLFormsResource):
1.21 +
1.22 + "A very simple resource providing a hierarchy of editable fields."
1.23 +
1.24 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
1.25 + encoding = "utf-8"
1.26 + template_resources = {
1.27 + "structure" : ("structure_template.xhtml", "structure_output.xsl")
1.28 + }
1.29 +
1.30 + def respond_to_form(self, trans, form):
1.31 +
1.32 + """
1.33 + Respond to a request having the given transaction 'trans' and the given
1.34 + 'form' information.
1.35 + """
1.36 +
1.37 + parameters = form.get_parameters()
1.38 + documents = form.get_documents()
1.39 +
1.40 + # Ensure the presence of a document.
1.41 +
1.42 + if documents.has_key("structure"):
1.43 + structure = documents["structure"]
1.44 + else:
1.45 + structure = form.new_instance("structure")
1.46 +
1.47 + # Add and remove elements according to the selectors found.
1.48 +
1.49 + selectors = form.get_selectors()
1.50 + XSLForms.Utils.remove_elements(selectors.get("remove2"))
1.51 + XSLForms.Utils.add_elements(selectors.get("add2"), "subitem")
1.52 + XSLForms.Utils.remove_elements(selectors.get("remove"))
1.53 + XSLForms.Utils.add_elements(selectors.get("add"), "item")
1.54 +
1.55 + # Start the response.
1.56 +
1.57 + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))
1.58 +
1.59 + # Ensure that an output stylesheet exists.
1.60 +
1.61 + trans_xsl = self.prepare_output("structure")
1.62 +
1.63 + # Complete the response.
1.64 +
1.65 + self.send_output(trans, [trans_xsl], structure)
1.66 +
1.67 +# Site map initialisation.
1.68 +
1.69 +def get_site():
1.70 +
1.71 + "Return a simple Web site resource."
1.72 +
1.73 + return VerySimpleResource()
1.74 +
1.75 +# vim: tabstop=4 expandtab shiftwidth=4