1.1 --- a/examples/Common/VerySimple/__init__.py Fri Jun 20 23:27:26 2008 +0000
1.2 +++ b/examples/Common/VerySimple/__init__.py Fri Jun 20 23:27:43 2008 +0000
1.3 @@ -3,8 +3,8 @@
1.4 "A very simple example application."
1.5
1.6 import WebStack.Generic
1.7 -import XSLForms.Resources.WebResources
1.8 -import XSLForms.Utils
1.9 +from XSLForms.Resources.WebResources import \
1.10 + XSLFormsResource, input, output, resources, prepare_resources as xslforms_prepare_resources
1.11 import os
1.12
1.13 # Site map imports.
1.14 @@ -19,20 +19,20 @@
1.15
1.16 # Resource classes.
1.17
1.18 -class VerySimpleResource(XSLForms.Resources.WebResources.XSLFormsResource):
1.19 +class VerySimpleResource(XSLFormsResource):
1.20
1.21 "A very simple resource providing a hierarchy of editable fields."
1.22
1.23 - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
1.24 + resource_dir = resources(__file__)
1.25 template_resources = {
1.26 - #"structure" : ("structure_template.xhtml", "structure_output.xsl")
1.27 - #"structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl")
1.28 - "structure" : ("structure_multivalue_label_template.xhtml", "structure_output.xsl")
1.29 + #"structure" : output("structure_template.xhtml")
1.30 + #"structure" : output("structure_multivalue_template.xhtml")
1.31 + "structure" : output("structure_multivalue_label_template.xhtml")
1.32 }
1.33 init_resources = {
1.34 - #"structure" : ("structure_template.xhtml", "structure_input.xsl")
1.35 - #"structure" : ("structure_multivalue_template.xhtml", "structure_input.xsl")
1.36 - "structure" : ("structure_multivalue_label_template.xhtml", "structure_input.xsl")
1.37 + #"structure" : input("structure_template.xhtml")
1.38 + #"structure" : input("structure_multivalue_template.xhtml")
1.39 + "structure" : input("structure_multivalue_label_template.xhtml")
1.40 }
1.41 transform_resources = {
1.42 "comments" : ["structure_comments.xsl"]
1.43 @@ -46,64 +46,51 @@
1.44 "comments" : ("structure", "structure_output_comments.xsl", "comment-node")
1.45 }
1.46
1.47 - def respond_to_form(self, trans, form):
1.48 -
1.49 - """
1.50 - Respond to a request having the given transaction 'trans' and the given
1.51 - 'form' information.
1.52 - """
1.53 + def select_activity(self, trans, form):
1.54 + form.set_activity("structure")
1.55
1.56 - in_page_resource = self.get_in_page_resource(trans)
1.57 - parameters = form.get_parameters()
1.58 - documents = form.get_documents()
1.59 -
1.60 - # Ensure the presence of a document.
1.61 -
1.62 - if documents.has_key("structure"):
1.63 - structure = documents["structure"]
1.64 - else:
1.65 - structure = form.new_instance("structure")
1.66 + def respond_to_input(self, trans, form):
1.67
1.68 # Add and remove elements according to the selectors found.
1.69
1.70 selectors = form.get_selectors()
1.71 - XSLForms.Utils.remove_elements(selectors.get("remove2"))
1.72 - XSLForms.Utils.add_elements(selectors.get("add2"), "subitem")
1.73 - XSLForms.Utils.remove_elements(selectors.get("remove"))
1.74 - XSLForms.Utils.add_elements(selectors.get("add"), "item")
1.75 + self.remove_elements(selectors.get("remove2"))
1.76 + self.add_elements(selectors.get("add2"), "subitem")
1.77 + self.remove_elements(selectors.get("remove"))
1.78 + self.add_elements(selectors.get("add"), "item")
1.79 +
1.80 + def init_document(self, trans, form):
1.81
1.82 - # Initialise the document, adding enumerations/ranges.
1.83 + # Transform, adding enumerations/ranges.
1.84
1.85 - structure_xsl = self.prepare_initialiser("structure")
1.86 types_xml = self.prepare_document("types")
1.87 - structure = self.get_result([structure_xsl], structure, references={"type" : types_xml})
1.88 + XSLFormsResource.init_document(self, trans, form, references={"type" : types_xml})
1.89 +
1.90 + def respond_to_document(self, trans, form):
1.91
1.92 # Add the comments.
1.93
1.94 comments_xsl_list = self.prepare_transform("comments")
1.95 - structure = self.get_result(comments_xsl_list, structure)
1.96 -
1.97 - # Start the response.
1.98 -
1.99 - trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", encoding))
1.100 + form.set_document(
1.101 + self.get_result(comments_xsl_list, form.get_document())
1.102 + )
1.103
1.104 - # Ensure that an output stylesheet exists.
1.105 -
1.106 - if in_page_resource in self.in_page_resources.keys():
1.107 - trans_xsl = self.prepare_fragment(in_page_resource)
1.108 - stylesheet_parameters = self.prepare_parameters(parameters)
1.109 - else:
1.110 - trans_xsl = self.prepare_output("structure")
1.111 - stylesheet_parameters = {}
1.112 + def create_output(self, trans, form):
1.113
1.114 # Complete the response.
1.115
1.116 + stylesheet_parameters = {}
1.117 +
1.118 try:
1.119 stylesheet_parameters["locale"] = trans.get_content_languages()[0]
1.120 except IndexError:
1.121 pass
1.122 - self.send_output(trans, [trans_xsl], structure, stylesheet_parameters,
1.123 - references={"translations" : self.prepare_document("translations")})
1.124 +
1.125 + XSLFormsResource.create_output(self, trans, form,
1.126 + stylesheet_parameters=stylesheet_parameters,
1.127 + references={
1.128 + "translations" : self.prepare_document("translations")
1.129 + })
1.130
1.131 # Site map initialisation.
1.132
1.133 @@ -131,6 +118,6 @@
1.134
1.135 def prepare_resources():
1.136 for cls in [VerySimpleResource]:
1.137 - XSLForms.Resources.WebResources.prepare_resources(cls)
1.138 + xslforms_prepare_resources(cls)
1.139
1.140 # vim: tabstop=4 expandtab shiftwidth=4