# HG changeset patch # User paulb # Date 1121990009 0 # Node ID a1f4594f58b46a4730b2973bfabb6986e3950214 # Parent e1a71337517ab7e27b14e99eb3b25231c1867f86 [project @ 2005-07-21 23:53:29 by paulb] Added in-page updates for comment fields. diff -r e1a71337517a -r a1f4594f58b4 examples/Common/VerySimple/__init__.py --- a/examples/Common/VerySimple/__init__.py Thu Jul 21 23:53:11 2005 +0000 +++ b/examples/Common/VerySimple/__init__.py Thu Jul 21 23:53:29 2005 +0000 @@ -7,6 +7,11 @@ 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): @@ -27,6 +32,9 @@ document_resources = { "types" : "structure_types.xml" } + in_page_resources = { + "comments" : ("structure_output_comments.xsl", "comment-node") + } def respond_to_form(self, trans, form): @@ -35,6 +43,8 @@ 'form' information. """ + in_page_resource = self.get_in_page_resource(trans) + parameters = form.get_parameters() documents = form.get_documents() # Ensure the presence of a document. @@ -62,13 +72,31 @@ trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding)) + # Define the stylesheet parameters. + + stylesheet_parameters = {} + # Ensure that an output stylesheet exists. - trans_xsl = self.prepare_output("structure") + if in_page_resource in self.in_page_resources.keys(): + trans_xsl = self.prepare_fragment("structure", in_page_resource) + element_path = parameters.get("element-path", [""])[0] + stylesheet_parameters["element-path"] = element_path + else: + trans_xsl = self.prepare_output("structure") + + # Add information essential for in-page requests. + + if trans.get_server_port() == "80": + stylesheet_parameters["application-url"] = \ + "http://%s%s" % (trans.get_server_name(), trans.get_path_without_query()) + else: + stylesheet_parameters["application-url"] = \ + "http://%s:%s%s" % (trans.get_server_name(), trans.get_server_port(), trans.get_path_without_query()) # Complete the response. - self.send_output(trans, [trans_xsl], structure) + self.send_output(trans, [trans_xsl], structure, stylesheet_parameters) # Site map initialisation. @@ -76,6 +104,22 @@ "Return a simple Web site resource." - return VerySimpleResource() + # Get the main resource and the directory used by the application. + + very_simple_resource = VerySimpleResource() + directory = very_simple_resource.resource_dir + + # Make a simple Web site. + + resource = MapResource({ + # Static resources: + "scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}), + # Main page: + "" : very_simple_resource, + # Fragments: + "comments" : very_simple_resource + }) + + return resource # vim: tabstop=4 expandtab shiftwidth=4