def render(self, data, media_type, **options): """ Just... Don't capitalize view_name! """ # noinspection PyUnresolvedReferences available_renderers = [ renderer for renderer in request.renderer_classes if not issubclass(renderer, BrowsableAPIRenderer) ] assert available_renderers, \ 'BrowsableAPIRenderer cannot be the only renderer' mock_renderer = available_renderers[0]() mock_media_type = MediaType(mock_renderer.media_type) if data == '' and not mock_renderer.handles_empty_responses: mock_content = None else: mock_content = mock_renderer.render(data, mock_media_type, indent=4) # Determine the allowed methods on this view. adapter = _request_ctx_stack.top.url_adapter allowed_methods = adapter.allowed_methods() endpoint = request.url_rule.endpoint view_name = str(endpoint) view_description = current_app.view_functions[endpoint].__doc__ if view_description is not None: view_description = dedent(view_description) mock_content = html_escape(mock_content) if view_description and apply_markdown: view_description = apply_markdown(view_description) status = options['status'] headers = options['headers'] headers['Content-Type'] = str(mock_media_type) from flask_api import __version__ context = { 'status': status, 'headers': headers, 'content': mock_content, 'allowed_methods': allowed_methods, 'view_name': view_name, 'view_description': view_description, 'version': __version__ } return render_template(self.template, **context)
def render(self, data, media_type, **options): # Render the content as it would have been if the client # had requested 'Accept: */*'. available_renderers = [ renderer for renderer in request.renderer_classes if not issubclass(renderer, BrowsableAPIRenderer) ] assert available_renderers, 'BrowsableAPIRenderer cannot be the only renderer' mock_renderer = available_renderers[0]() mock_media_type = MediaType(mock_renderer.media_type) if data == '' and not mock_renderer.handles_empty_responses: mock_content = None else: text = mock_renderer.render(data, mock_media_type, indent=4) mock_content = self._html_escape(text) # Determine the allowed methods on this view. adapter = _request_ctx_stack.top.url_adapter allowed_methods = adapter.allowed_methods() endpoint = request.url_rule.endpoint view_name = str(endpoint) view_description = current_app.view_functions[endpoint].__doc__ if view_description: if apply_markdown: view_description = dedent(view_description) view_description = apply_markdown(view_description) else: # pragma: no cover - markdown installed for tests view_description = dedent(view_description) view_description = pydoc.html.preformat(view_description) status = options['status'] headers = options['headers'] headers['Content-Type'] = str(mock_media_type) from flask_api import __version__ context = { 'status': status, 'headers': headers, 'content': mock_content, 'allowed_methods': allowed_methods, 'view_name': convert_to_title(view_name), 'view_description': view_description, 'version': __version__ } return render_template(self.template, **context)
def render(self, data, media_type, **options): # Render the content as it would have been if the client # had requested 'Accept: */*'. available_renderers = [ renderer for renderer in request.renderer_classes if not issubclass(renderer, BrowsableAPIRenderer) ] assert available_renderers, 'BrowsableAPIRenderer cannot be the only renderer' mock_renderer = available_renderers[0]() mock_media_type = MediaType(mock_renderer.media_type) if data == '' and not mock_renderer.handles_empty_responses: mock_content = None else: text = mock_renderer.render(data, mock_media_type, indent=4) mock_content = self._html_escape(text) # Determine the allowed methods on this view. adapter = _request_ctx_stack.top.url_adapter allowed_methods = adapter.allowed_methods() endpoint = request.url_rule.endpoint view_name = str(endpoint) view_description = current_app.view_functions[endpoint].__doc__ if view_description: if apply_markdown: view_description = dedent(view_description) view_description = apply_markdown(view_description) else: # pragma: no cover - markdown installed for tests view_description = dedent(view_description) view_description = pydoc.html.preformat(view_description) status = options['status'] headers = options['headers'] headers['Content-Type'] = str(mock_media_type) from flask_api import __version__ context = { 'status': status, 'headers': headers, 'content': mock_content, 'allowed_methods': allowed_methods, 'view_name': convert_to_title(view_name), 'view_description': view_description, 'version': __version__ } return render_template(self.template, **context)