1.1 --- a/examples/Common/Candidate/__init__.py Wed Nov 16 17:50:04 2005 +0000
1.2 +++ b/examples/Common/Candidate/__init__.py Wed Nov 16 17:52:02 2005 +0000
1.3 @@ -42,9 +42,9 @@
1.4 # Get the "show" and "edit" resource paths.
1.5 # NOTE: These should be obtained from the site map.
1.6
1.7 - parts = trans.get_processed_virtual_path_info(self.path_encoding).split("/")
1.8 - show_path = "/".join(parts[:-1] + ["show"])
1.9 - edit_path = "/".join(parts[:-1] + ["edit"])
1.10 + vpath = trans.get_processed_virtual_path_info(self.path_encoding)
1.11 + show_path = trans.get_path_without_info(self.path_encoding) + trans.update_path(vpath, "show")
1.12 + edit_path = trans.get_path_without_info(self.path_encoding) + trans.update_path(vpath, "edit")
1.13
1.14 # Ensure the presence of a document.
1.15
1.16 @@ -60,10 +60,12 @@
1.17 selectors = form.get_selectors()
1.18 if selectors.has_key("show"):
1.19 name = selectors["show"][0].getAttribute("name")
1.20 - self._redirect(trans, show_path + "?name=%s" % name.encode(self.path_encoding))
1.21 + trans.redirect(trans.encode_path(show_path, self.path_encoding) +
1.22 + "?name=%s" % trans.encode_path(name, self.path_encoding))
1.23 elif selectors.has_key("edit"):
1.24 name = selectors["edit"][0].getAttribute("name")
1.25 - self._redirect(trans, edit_path + "?name=%s" % name.encode(self.path_encoding))
1.26 + trans.redirect(trans.encode_path(edit_path, self.path_encoding) +
1.27 + "?name=%s" % trans.encode_path(name, self.path_encoding))
1.28
1.29 # Add and remove elements according to the selectors found.
1.30
1.31 @@ -75,12 +77,11 @@
1.32 init_xsl = self.prepare_initialiser("admin")
1.33 admin = self.get_result([init_xsl], admin)
1.34
1.35 - # Synchronise the session with the CVs found.
1.36 + # Synchronise the repository with the CVs found.
1.37
1.38 cvs = admin.xpath("/admin/cvs")[0]
1.39 - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.40 - #session = trans.get_session()
1.41 - for key in session.keys():
1.42 + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.43 + for key in repository.keys():
1.44 if key.startswith("candidate-"):
1.45 name = key[len("candidate-"):]
1.46 # NOTE: Apostrophes not quoted.
1.47 @@ -90,7 +91,7 @@
1.48 cv.setAttribute("name", name)
1.49 cvs.appendChild(cv)
1.50 else:
1.51 - del session[key]
1.52 + del repository[key]
1.53
1.54 # Start the response.
1.55
1.56 @@ -105,11 +106,6 @@
1.57
1.58 self.send_output(trans, [trans_xsl], admin, stylesheet_parameters)
1.59
1.60 - def _redirect(self, trans, path):
1.61 - trans.set_response_code(302)
1.62 - trans.set_header_value("Location", path)
1.63 - raise WebStack.Generic.EndOfResponse
1.64 -
1.65 class DisplayResource(XSLForms.Resources.WebResources.XSLFormsResource):
1.66
1.67 "A resource providing editing facilities for a job candidate profile."
1.68 @@ -135,7 +131,7 @@
1.69
1.70 parameters = form.get_parameters()
1.71 documents = form.get_documents()
1.72 - fields = trans.get_fields_from_path()
1.73 + fields = trans.get_fields_from_path(self.path_encoding)
1.74 name = fields.get("name", [u"None"])[0]
1.75
1.76 # Ensure the presence of a document.
1.77 @@ -143,12 +139,11 @@
1.78 if documents.has_key("candidate"):
1.79 candidate = documents["candidate"]
1.80 else:
1.81 - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.82 - #session = trans.get_session(create=0)
1.83 - if session is None or not session.has_key("candidate-%s" % name.encode("utf-8")):
1.84 + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.85 + if repository is None or not repository.has_key("candidate-%s" % name):
1.86 candidate = form.new_instance("candidate")
1.87 else:
1.88 - candidate = libxml2dom.parseString(session["candidate-%s" % name.encode("utf-8")])
1.89 + candidate = libxml2dom.parseString(repository["candidate-%s" % name])
1.90
1.91 # Transform, adding enumerations/ranges.
1.92
1.93 @@ -195,27 +190,26 @@
1.94
1.95 parameters = form.get_parameters()
1.96 documents = form.get_documents()
1.97 - fields = trans.get_fields_from_path()
1.98 + fields = trans.get_fields_from_path(self.path_encoding)
1.99 name = fields.get("name", [u"None"])[0]
1.100
1.101 # Get the "show" resource path.
1.102 # NOTE: This should be obtained from the site map.
1.103
1.104 - parts = trans.get_processed_virtual_path_info(self.path_encoding).split("/")
1.105 - show_path = "/".join(parts[:-1] + ["show"])
1.106 - admin_path = "/".join(parts[:-1] + [""])
1.107 + vpath = trans.get_processed_virtual_path_info(self.path_encoding)
1.108 + show_path = trans.get_path_without_info(self.path_encoding) + trans.update_path(vpath, "show")
1.109 + admin_path = trans.get_path_without_info(self.path_encoding) + trans.update_path(vpath, "")
1.110
1.111 # Ensure the presence of a document.
1.112
1.113 if documents.has_key("candidate"):
1.114 candidate = documents["candidate"]
1.115 else:
1.116 - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.117 - #session = trans.get_session(create=0)
1.118 - if session is None or not session.has_key("candidate-%s" % name.encode("utf-8")):
1.119 + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.120 + if repository is None or not repository.has_key("candidate-%s" % name):
1.121 candidate = form.new_instance("candidate")
1.122 else:
1.123 - candidate = libxml2dom.parseString(session["candidate-%s" % name.encode("utf-8")])
1.124 + candidate = libxml2dom.parseString(repository["candidate-%s" % name])
1.125
1.126 # Add and remove elements according to the selectors found.
1.127
1.128 @@ -237,10 +231,10 @@
1.129
1.130 # Save the candidate information.
1.131
1.132 - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.133 - #session = trans.get_session()
1.134 - session["candidate-%s" % name.encode("utf-8")] = candidate.toString()
1.135 - self._redirect(trans, show_path + "?name=%s" % name.encode(self.path_encoding))
1.136 + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.137 + repository["candidate-%s" % name] = candidate.toString()
1.138 + trans.redirect(trans.encode_path(show_path, self.path_encoding) +
1.139 + "?name=%s" % trans.encode_path(name, self.path_encoding))
1.140
1.141 # Redirect if the administration interface is to be used.
1.142
1.143 @@ -248,10 +242,9 @@
1.144
1.145 # Save the candidate information.
1.146
1.147 - session = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.148 - #session = trans.get_session()
1.149 - session["candidate-%s" % name.encode("utf-8")] = candidate.toString()
1.150 - self._redirect(trans, admin_path)
1.151 + repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.152 + repository["candidate-%s" % name] = candidate.toString()
1.153 + trans.redirect(trans.encode_path(admin_path, self.path_encoding))
1.154
1.155 # Start the response.
1.156
1.157 @@ -266,11 +259,6 @@
1.158
1.159 self.send_output(trans, [trans_xsl], candidate, stylesheet_parameters)
1.160
1.161 - def _redirect(self, trans, path):
1.162 - trans.set_response_code(302)
1.163 - trans.set_header_value("Location", path)
1.164 - raise WebStack.Generic.EndOfResponse
1.165 -
1.166 # Site map initialisation.
1.167
1.168 def get_site():