# HG changeset patch # User paulb # Date 1132163522 0 # Node ID 13a177cf419dcf3e80915469db958da4b66adc15 # Parent fde1d1a9579e0497465ea9648773ec75b30a0ebf [project @ 2005-11-16 17:52:02 by paulb] Updated the code to use WebStack 1.1 transaction methods such as those related to path manipulation and redirection. Fixed various redirect paths using the encode_path transaction method. Removed traces of sessions, along with now-unnecessary conversions from Unicode. diff -r fde1d1a9579e -r 13a177cf419d examples/Common/Candidate/__init__.py --- a/examples/Common/Candidate/__init__.py Wed Nov 16 17:50:04 2005 +0000 +++ b/examples/Common/Candidate/__init__.py Wed Nov 16 17:52:02 2005 +0000 @@ -42,9 +42,9 @@ # Get the "show" and "edit" resource paths. # NOTE: These should be obtained from the site map. - parts = trans.get_processed_virtual_path_info(self.path_encoding).split("/") - show_path = "/".join(parts[:-1] + ["show"]) - edit_path = "/".join(parts[:-1] + ["edit"]) + vpath = trans.get_processed_virtual_path_info(self.path_encoding) + show_path = trans.get_path_without_info(self.path_encoding) + trans.update_path(vpath, "show") + edit_path = trans.get_path_without_info(self.path_encoding) + trans.update_path(vpath, "edit") # Ensure the presence of a document. @@ -60,10 +60,12 @@ selectors = form.get_selectors() if selectors.has_key("show"): name = selectors["show"][0].getAttribute("name") - self._redirect(trans, show_path + "?name=%s" % name.encode(self.path_encoding)) + trans.redirect(trans.encode_path(show_path, self.path_encoding) + + "?name=%s" % trans.encode_path(name, self.path_encoding)) elif selectors.has_key("edit"): name = selectors["edit"][0].getAttribute("name") - self._redirect(trans, edit_path + "?name=%s" % name.encode(self.path_encoding)) + trans.redirect(trans.encode_path(edit_path, self.path_encoding) + + "?name=%s" % trans.encode_path(name, self.path_encoding)) # Add and remove elements according to the selectors found. @@ -75,12 +77,11 @@ init_xsl = self.prepare_initialiser("admin") admin = self.get_result([init_xsl], admin) - # Synchronise the session with the CVs found. + # Synchronise the repository with the CVs found. cvs = admin.xpath("/admin/cvs")[0] - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) - #session = trans.get_session() - for key in session.keys(): + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) + for key in repository.keys(): if key.startswith("candidate-"): name = key[len("candidate-"):] # NOTE: Apostrophes not quoted. @@ -90,7 +91,7 @@ cv.setAttribute("name", name) cvs.appendChild(cv) else: - del session[key] + del repository[key] # Start the response. @@ -105,11 +106,6 @@ self.send_output(trans, [trans_xsl], admin, stylesheet_parameters) - def _redirect(self, trans, path): - trans.set_response_code(302) - trans.set_header_value("Location", path) - raise WebStack.Generic.EndOfResponse - class DisplayResource(XSLForms.Resources.WebResources.XSLFormsResource): "A resource providing editing facilities for a job candidate profile." @@ -135,7 +131,7 @@ parameters = form.get_parameters() documents = form.get_documents() - fields = trans.get_fields_from_path() + fields = trans.get_fields_from_path(self.path_encoding) name = fields.get("name", [u"None"])[0] # Ensure the presence of a document. @@ -143,12 +139,11 @@ if documents.has_key("candidate"): candidate = documents["candidate"] else: - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) - #session = trans.get_session(create=0) - if session is None or not session.has_key("candidate-%s" % name.encode("utf-8")): + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) + if repository is None or not repository.has_key("candidate-%s" % name): candidate = form.new_instance("candidate") else: - candidate = libxml2dom.parseString(session["candidate-%s" % name.encode("utf-8")]) + candidate = libxml2dom.parseString(repository["candidate-%s" % name]) # Transform, adding enumerations/ranges. @@ -195,27 +190,26 @@ parameters = form.get_parameters() documents = form.get_documents() - fields = trans.get_fields_from_path() + fields = trans.get_fields_from_path(self.path_encoding) name = fields.get("name", [u"None"])[0] # Get the "show" resource path. # NOTE: This should be obtained from the site map. - parts = trans.get_processed_virtual_path_info(self.path_encoding).split("/") - show_path = "/".join(parts[:-1] + ["show"]) - admin_path = "/".join(parts[:-1] + [""]) + vpath = trans.get_processed_virtual_path_info(self.path_encoding) + show_path = trans.get_path_without_info(self.path_encoding) + trans.update_path(vpath, "show") + admin_path = trans.get_path_without_info(self.path_encoding) + trans.update_path(vpath, "") # Ensure the presence of a document. if documents.has_key("candidate"): candidate = documents["candidate"] else: - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) - #session = trans.get_session(create=0) - if session is None or not session.has_key("candidate-%s" % name.encode("utf-8")): + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) + if repository is None or not repository.has_key("candidate-%s" % name): candidate = form.new_instance("candidate") else: - candidate = libxml2dom.parseString(session["candidate-%s" % name.encode("utf-8")]) + candidate = libxml2dom.parseString(repository["candidate-%s" % name]) # Add and remove elements according to the selectors found. @@ -237,10 +231,10 @@ # Save the candidate information. - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) - #session = trans.get_session() - session["candidate-%s" % name.encode("utf-8")] = candidate.toString() - self._redirect(trans, show_path + "?name=%s" % name.encode(self.path_encoding)) + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) + repository["candidate-%s" % name] = candidate.toString() + trans.redirect(trans.encode_path(show_path, self.path_encoding) + + "?name=%s" % trans.encode_path(name, self.path_encoding)) # Redirect if the administration interface is to be used. @@ -248,10 +242,9 @@ # Save the candidate information. - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) - #session = trans.get_session() - session["candidate-%s" % name.encode("utf-8")] = candidate.toString() - self._redirect(trans, admin_path) + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates")) + repository["candidate-%s" % name] = candidate.toString() + trans.redirect(trans.encode_path(admin_path, self.path_encoding)) # Start the response. @@ -266,11 +259,6 @@ self.send_output(trans, [trans_xsl], candidate, stylesheet_parameters) - def _redirect(self, trans, path): - trans.set_response_code(302) - trans.set_header_value("Location", path) - raise WebStack.Generic.EndOfResponse - # Site map initialisation. def get_site():