def set_haunted_url(self, content_url): """Set content url. """ pad = PathAdapter(self.REQUEST) path = pad.urlToPath(content_url) path_elements = path.split('/') # Cut off 'edit' and anything after it try: idx = path_elements.index('edit') except ValueError: pass else: path_elements = path_elements[:idx] if path_elements[0] == '': traversal_root = self.get_root() else: traversal_root = self.get_container() # Now resolve it... target = traversal_root.unrestrictedTraverse(path_elements, None) if target is None: (scheme, netloc, path, parameters, query, fragment) = \ urlparse.urlparse(content_url) self._content_path = path.split('/') else: # ...and get physical path for it self._content_path = target.getPhysicalPath()
def get_haunted_url(self): """Get content url. """ if self._content_path is None: return None object = self.get_root().unrestrictedTraverse(self._content_path, None) if object is None: return '/'.join(self._content_path) pad = PathAdapter(self.REQUEST) url = pad.pathToUrlPath('/'.join(object.getPhysicalPath())) return url