1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/VerySimple/Resources/structure_template.xhtml Sun Jul 17 22:35:19 2005 +0000
1.3 @@ -0,0 +1,42 @@
1.4 +<?xml version="1.0" encoding="iso-8859-1"?>
1.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
1.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
1.7 +<html xmlns="http://www.w3.org/1999/xhtml"
1.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
1.9 +<head>
1.10 + <title>Example</title>
1.11 +</head>
1.12 +<body template:element="structure">
1.13 +<form action="" method="POST">
1.14 +
1.15 +<!-- Template text between the start and the interesting part. -->
1.16 +
1.17 +<div template:element="item">
1.18 + <p>
1.19 + <span template:attribute="value">
1.20 + Some item: <input name="{template:field-name()}" type="text" value="{$this-value}" />
1.21 + </span>
1.22 + <input name="remove={template:this-position()}" type="submit" value="Remove" />
1.23 + </p>
1.24 + <p>
1.25 + Itself containing more items:
1.26 + </p>
1.27 + <p template:element="subitem">
1.28 + <span template:attribute="subvalue">
1.29 + Sub-item: <input name="{template:field-name()}" type="text" value="{$this-value}" />
1.30 + </span>
1.31 + <input name="remove2={template:this-position()}" type="submit" value="Remove" />
1.32 + </p>
1.33 + <p>
1.34 + <input name="add2={template:this-position()}" type="submit" value="Add subitem" />
1.35 + </p>
1.36 +</div>
1.37 +<p>
1.38 + <input name="add={template:this-position()}" type="submit" value="Add item" />
1.39 +</p>
1.40 +
1.41 +<!-- Template text between the interesting part and the end. -->
1.42 +
1.43 +</form>
1.44 +</body>
1.45 +</html>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/Common/VerySimple/__init__.py Sun Jul 17 22:35:19 2005 +0000
2.3 @@ -0,0 +1,72 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"A very simple example application."
2.7 +
2.8 +import WebStack.Generic
2.9 +import XSLForms.Resources
2.10 +import XSLForms.Utils
2.11 +import os
2.12 +
2.13 +# Site map imports.
2.14 +
2.15 +from WebStack.Resources.ResourceMap import MapResource
2.16 +from WebStack.Resources.Static import DirectoryResource
2.17 +
2.18 +# Resource classes.
2.19 +
2.20 +class VerySimpleResource(XSLForms.Resources.XSLFormsResource):
2.21 +
2.22 + "A very simple resource providing a hierarchy of editable fields."
2.23 +
2.24 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
2.25 + encoding = "utf-8"
2.26 + template_resources = {
2.27 + "structure" : ("structure_template.xhtml", "structure_output.xsl")
2.28 + }
2.29 +
2.30 + def respond_to_form(self, trans, form):
2.31 +
2.32 + """
2.33 + Respond to a request having the given transaction 'trans' and the given
2.34 + 'form' information.
2.35 + """
2.36 +
2.37 + parameters = form.get_parameters()
2.38 + documents = form.get_documents()
2.39 +
2.40 + # Ensure the presence of a document.
2.41 +
2.42 + if documents.has_key("structure"):
2.43 + structure = documents["structure"]
2.44 + else:
2.45 + structure = form.new_instance("structure")
2.46 +
2.47 + # Add and remove elements according to the selectors found.
2.48 +
2.49 + selectors = form.get_selectors()
2.50 + XSLForms.Utils.remove_elements(selectors.get("remove2"))
2.51 + XSLForms.Utils.add_elements(selectors.get("add2"), "subitem")
2.52 + XSLForms.Utils.remove_elements(selectors.get("remove"))
2.53 + XSLForms.Utils.add_elements(selectors.get("add"), "item")
2.54 +
2.55 + # Start the response.
2.56 +
2.57 + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))
2.58 +
2.59 + # Ensure that an output stylesheet exists.
2.60 +
2.61 + trans_xsl = self.prepare_output("structure")
2.62 +
2.63 + # Complete the response.
2.64 +
2.65 + self.send_output(trans, [trans_xsl], structure)
2.66 +
2.67 +# Site map initialisation.
2.68 +
2.69 +def get_site():
2.70 +
2.71 + "Return a simple Web site resource."
2.72 +
2.73 + return VerySimpleResource()
2.74 +
2.75 +# vim: tabstop=4 expandtab shiftwidth=4