# HG changeset patch # User paulb # Date 1214004463 0 # Node ID 2ee0853b91649ff50d31ca48796d818e83dcd1cc # Parent 3df7a67417de62bed7cbfcc386abff2290e7e52b [project @ 2008-06-20 23:27:43 by paulb] Converted the example to the "modular" API. diff -r 3df7a67417de -r 2ee0853b9164 examples/Common/VerySimple/__init__.py --- a/examples/Common/VerySimple/__init__.py Fri Jun 20 23:27:26 2008 +0000 +++ b/examples/Common/VerySimple/__init__.py Fri Jun 20 23:27:43 2008 +0000 @@ -3,8 +3,8 @@ "A very simple example application." import WebStack.Generic -import XSLForms.Resources.WebResources -import XSLForms.Utils +from XSLForms.Resources.WebResources import \ + XSLFormsResource, input, output, resources, prepare_resources as xslforms_prepare_resources import os # Site map imports. @@ -19,20 +19,20 @@ # Resource classes. -class VerySimpleResource(XSLForms.Resources.WebResources.XSLFormsResource): +class VerySimpleResource(XSLFormsResource): "A very simple resource providing a hierarchy of editable fields." - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") + resource_dir = resources(__file__) template_resources = { - #"structure" : ("structure_template.xhtml", "structure_output.xsl") - #"structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl") - "structure" : ("structure_multivalue_label_template.xhtml", "structure_output.xsl") + #"structure" : output("structure_template.xhtml") + #"structure" : output("structure_multivalue_template.xhtml") + "structure" : output("structure_multivalue_label_template.xhtml") } init_resources = { - #"structure" : ("structure_template.xhtml", "structure_input.xsl") - #"structure" : ("structure_multivalue_template.xhtml", "structure_input.xsl") - "structure" : ("structure_multivalue_label_template.xhtml", "structure_input.xsl") + #"structure" : input("structure_template.xhtml") + #"structure" : input("structure_multivalue_template.xhtml") + "structure" : input("structure_multivalue_label_template.xhtml") } transform_resources = { "comments" : ["structure_comments.xsl"] @@ -46,64 +46,51 @@ "comments" : ("structure", "structure_output_comments.xsl", "comment-node") } - def respond_to_form(self, trans, form): - - """ - Respond to a request having the given transaction 'trans' and the given - 'form' information. - """ + def select_activity(self, trans, form): + form.set_activity("structure") - in_page_resource = self.get_in_page_resource(trans) - 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") + def respond_to_input(self, trans, form): # 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") + self.remove_elements(selectors.get("remove2")) + self.add_elements(selectors.get("add2"), "subitem") + self.remove_elements(selectors.get("remove")) + self.add_elements(selectors.get("add"), "item") + + def init_document(self, trans, form): - # Initialise the document, adding enumerations/ranges. + # Transform, adding enumerations/ranges. - structure_xsl = self.prepare_initialiser("structure") types_xml = self.prepare_document("types") - structure = self.get_result([structure_xsl], structure, references={"type" : types_xml}) + XSLFormsResource.init_document(self, trans, form, references={"type" : types_xml}) + + def respond_to_document(self, trans, form): # Add the comments. comments_xsl_list = self.prepare_transform("comments") - structure = self.get_result(comments_xsl_list, structure) - - # Start the response. - - trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", encoding)) + form.set_document( + self.get_result(comments_xsl_list, form.get_document()) + ) - # Ensure that an output stylesheet exists. - - if in_page_resource in self.in_page_resources.keys(): - trans_xsl = self.prepare_fragment(in_page_resource) - stylesheet_parameters = self.prepare_parameters(parameters) - else: - trans_xsl = self.prepare_output("structure") - stylesheet_parameters = {} + def create_output(self, trans, form): # Complete the response. + stylesheet_parameters = {} + try: stylesheet_parameters["locale"] = trans.get_content_languages()[0] except IndexError: pass - self.send_output(trans, [trans_xsl], structure, stylesheet_parameters, - references={"translations" : self.prepare_document("translations")}) + + XSLFormsResource.create_output(self, trans, form, + stylesheet_parameters=stylesheet_parameters, + references={ + "translations" : self.prepare_document("translations") + }) # Site map initialisation. @@ -131,6 +118,6 @@ def prepare_resources(): for cls in [VerySimpleResource]: - XSLForms.Resources.WebResources.prepare_resources(cls) + xslforms_prepare_resources(cls) # vim: tabstop=4 expandtab shiftwidth=4