1.1 --- a/examples/Common/Configurator/__init__.py Thu Jul 14 21:38:44 2005 +0000
1.2 +++ b/examples/Common/Configurator/__init__.py Thu Jul 14 21:39:35 2005 +0000
1.3 @@ -3,15 +3,15 @@
1.4 "A WebStack application for a system configurator."
1.5
1.6 import WebStack.Generic
1.7 -import XSLForms.Fields
1.8 import XSLForms.Output
1.9 import XSLForms.Prepare
1.10 import XSLForms.Utils
1.11 +import XSLForms.Resources
1.12 import XSLOutput
1.13 import libxml2dom
1.14 import os
1.15
1.16 -class ConfiguratorResource:
1.17 +class ConfiguratorResource(XSLForms.Resources.XSLFormsResource):
1.18
1.19 "A resource providing a system configurator."
1.20
1.21 @@ -23,61 +23,28 @@
1.22 "/hard-disks" : ("config_output_harddisks.xsl", "hard-disks-node")
1.23 }
1.24
1.25 - def get_fields_from_body(self, trans, encoding):
1.26 - text = trans.get_request_stream().read().decode(encoding)
1.27 - parameters = {}
1.28 - for text_line in text.split("\r\n"):
1.29 - text_parts = text_line.split("=")
1.30 - text_name, text_value = text_parts[0], "=".join(text_parts[1:])
1.31 - if not parameters.has_key(text_name):
1.32 - parameters[text_name] = []
1.33 - # NOTE: Workaround from posted text.
1.34 - if text_value[-1] == "\x00":
1.35 - text_value = text_value[:-1]
1.36 - parameters[text_name].append(text_value)
1.37 - return parameters
1.38 + def respond_to_form(self, trans, form):
1.39
1.40 - def respond(self, trans):
1.41 -
1.42 - global XSLForms # NOTE: Strangely required to avoid UnboundLocalError!
1.43 + """
1.44 + Respond to a request having the given transaction 'trans' and the given
1.45 + 'form' information.
1.46 + """
1.47
1.48 - # Only obtain field information according to the stated method.
1.49 -
1.50 - method = trans.get_request_method()
1.51 path_info = trans.get_path_info()
1.52 -
1.53 - if method == "GET":
1.54 - fields = XSLForms.Fields.Fields(encoding="iso-8859-1", values_are_lists=1)
1.55 - parameters = trans.get_fields_from_path()
1.56 - documents = fields.make_documents(parameters.items())
1.57 - elif method == "POST":
1.58 - fields = XSLForms.Fields.Fields(encoding=self.encoding, values_are_lists=1)
1.59 -
1.60 - # Handle requests for fragments.
1.61 -
1.62 - if path_info in self.in_page_resources.keys():
1.63 - parameters = self.get_fields_from_body(trans, self.encoding)
1.64 - else:
1.65 - parameters = trans.get_fields_from_body(self.encoding)
1.66 -
1.67 - # Get the XML representation of the request.
1.68 -
1.69 - documents = fields.make_documents(parameters.items())
1.70 - else:
1.71 - trans.set_response_code(405)
1.72 - raise WebStack.Generic.EndOfResponse
1.73 + parameters = form.get_parameters()
1.74 + documents = form.get_documents()
1.75 + selectors = form.get_selectors()
1.76
1.77 # Ensure the presence of a document.
1.78
1.79 if documents.has_key("configuration"):
1.80 configuration = documents["configuration"]
1.81 else:
1.82 - configuration = fields.new_instance("configuration")
1.83 + configuration = form.new_instance("configuration")
1.84 #print "*", configuration.toString()
1.85
1.86 # Add and remove elements according to the selectors found.
1.87
1.88 - selectors = fields.get_selectors(parameters.items(), documents)
1.89 XSLForms.Utils.add_elements(selectors.get("add-memory-unit"), "memory-unit")
1.90 XSLForms.Utils.remove_elements(selectors.get("remove-memory-unit"))
1.91 XSLForms.Utils.add_elements(selectors.get("add-storage-unit"), "storage-unit")