def render_module(self, name, variables): base, target = self.find_longest_module(name, variables) variables['base_path'] = base variables['sub_path'] = name[len(base)+1:] sessions.load_session(variables) context = RequestDict(variables) if target: try: actions = target.__dict__ func = actions.get(context.method, None) or actions['run'] except KeyError: return self.render_error(500, 'No run method or %s method.' % context.method) result = func(context) session_headers = {} sessions.save_session(variables, session_headers) if isinstance(result, tuple): body, code, headers = result headers.update(session_headers) return body, code, headers else: session_headers['Content-type'] = self.default_mtype return result, 200, session_headers else: return self.render_error(404, "Not Found", variables=variables)
def render_module(self, name, variables): base, target = self.find_longest_module(name, variables) if not (base and target): return self.render_error(404, "Not Found", variables=variables) variables['base_path'] = base variables['sub_path'] = name[len(base)+1:] sessions.load_session(variables) context = RequestDict(variables) if target: try: actions = target.__dict__ func = actions.get(context.method, None) or actions['run'] except KeyError: return self.render_error(500, 'No run method or %s method.' % context.method) result = func(context) session_headers = {} sessions.save_session(variables, session_headers) if isinstance(result, tuple): body, code, headers = result headers.update(session_headers) return body, code, headers else: session_headers['Content-type'] = self.default_mtype return result, 200, session_headers else: return self.render_error(404, "Not Found", variables=variables)
def render_template(self, path, variables, ext=None): ext = ext or os.path.splitext(path)[1] headers = tools.make_ctype(ext, self.default_mtype) if 'headers' in variables: sessions.load_session(variables) context = {'web': variables, 'module': tools.module, 'response_headers': headers } template = self.env.get_template(path) result = template.render(**context) if 'headers' in variables: sessions.save_session(variables, headers) return result, 200, headers