def get_namespace(self, resource, context): path = context.query['path'] if path is None: path = Path('.') if path.startswith_slash: path.startswith_slash = False # Namespace: the location base = '/%s/;browse_tests' % context.site_root.get_pathto(resource) link = base + '?path=%s' location = [{'name': MSG(u'Test Suite'), 'link': link % '.'}] for i, name in enumerate(path): p = path[:i+1] try: test_suite.get_handler(p) except LookupError: location.append({'name': name, 'link': None}) body = MSG(u'The "{path}" resource has not been found') body = body.gettext(path=p) return {'location': location, 'body': body} else: location.append({'name': name, 'link': link % p}) # Get the handler handler = test_suite.get_handler(path) # (1) View PO file root = context.root if isinstance(handler, POFile): template = root.get_resource('/ui/odf-i18n/view_po.xml') units = handler.get_units() msgs = [ {'id': x.source, 'str': x.target} for x in units ] namespace = {'messages': msgs} body = stl(template, namespace) return {'location': location, 'body': body} # Load setup file if handler.has_handler('setup.conf'): setup = handler.get_handler('setup.conf', cls=ConfigFile) else: setup = None # (2) Browse Folders children = handler.get_handler_names() children.sort() a_handler = handler.get_handler(children[0]) if isinstance(a_handler, Folder): files = [] for child in children: child_handler = handler.get_handler(child) number = 0 for x in test_suite.database.fs.traverse(child_handler.key): if x.endswith('.po'): number += 1 files.append({'child_name': child, 'to_child': link % ('%s/%s' % (path, child)), 'number': number}) namespace = {'content': files} template = root.get_resource('/ui/odf-i18n/browse_folder.xml') body = stl(template, namespace) return {'location': location, 'body': body} # (3) Test Folder if setup is None: title = description = reference = url_reference = None else: title = setup.get_value('title') description = setup.get_value('description') reference = setup.get_value('reference') url_reference = setup.get_value('url_reference') # Format the description (may contain XML) description = XMLParser(description) files = [] for child in children: if child != 'setup.conf': child_path = '%s/%s' % (path, child) view = (link % child_path) if child.endswith('.po') else None files.append({ 'child_name': child, 'view': view, 'to_child': ';download?path=%s' % child_path}) template = root.get_resource('/ui/odf-i18n/browse_test.xml') namespace = { 'title': title, 'description': description, 'reference': reference, 'url_reference': url_reference, 'content': files} body = stl(template, namespace) return {'location': location, 'body': body}