def contrib(request, arg1, arg2=None, arg3=None, arg4=None): messages = [] errors = [] full_path = get_template_name(adagios.settings.contrib_dir, arg1, arg2, arg3, arg4) if os.path.isdir(full_path): return index(request, contrib_dir=full_path) with open(full_path) as f: content = f.read() # Lets populate local namespace with convenient data services = lambda: locals().get('services', adagios.status.utils.get_services(request)) hosts = lambda: locals().get('hosts', adagios.status.utils.get_hosts(request)) service_problems = lambda: locals().get( 'service_problems', adagios.status.utils.get_hosts(request, state__isnot='0')) host_problems = lambda: locals().get( 'host_problems', adagios.status.utils.get_hosts(request, state__isnot='0')) statistics = lambda: locals().get( 'statistics', adagios.status.utils.get_statistics(request)) t = template.Template(content) c = template.Context(locals()) html = t.render(c) return HttpResponse(html)
def testGetTemplateFilename(self): base_path = self.base_path file1 = base_path + '/file1' dir1 = base_path + '/dir1' file2 = dir1 + '/file2' open(file1, 'w').write('this is file1') os.mkdir(dir1) open(file2, 'w').write('this is file2') self.assertEqual(file1, get_template_name(base_path, 'file1')) self.assertEqual(file2, get_template_name(base_path, 'dir1', 'file2')) self.assertEqual(file2, get_template_name(base_path, 'dir1', 'file2', 'unneeded_argument')) # Try to return a filename that is outside base_path exception1 = lambda: get_template_name(base_path, '/etc/passwd') self.assertRaises(Exception, exception1) # Try to return a filename that is outside base_path exception2 = lambda: get_template_name(base_path, '/etc/', 'passwd') self.assertRaises(Exception, exception2) # Try to return a filename that is outside base_path exception3 = lambda: get_template_name(base_path, '..', 'passwd') self.assertRaises(Exception, exception3)
def contrib(request, arg1, arg2=None, arg3=None, arg4=None): messages = [] errors = [] full_path = get_template_name(adagios.settings.contrib_dir, arg1, arg2, arg3, arg4) if os.path.isdir(full_path): return index(request, contrib_dir=full_path) with open(full_path) as f: content = f.read() # Lets populate local namespace with convenient data services = lambda: locals().get('services', adagios.status.utils.get_services(request)) hosts = lambda: locals().get('hosts', adagios.status.utils.get_hosts(request)) service_problems = lambda: locals().get('service_problems', adagios.status.utils.get_hosts(request, state__isnot='0')) host_problems = lambda: locals().get('host_problems', adagios.status.utils.get_hosts(request, state__isnot='0')) statistics = lambda: locals().get('statistics', adagios.status.utils.get_statistics(request)) t = template.Template(content) c = template.Context(locals()) html = t.render(c) return HttpResponse(html)