def _wrapped_view(request, *args, **kwargs): enable_instrumentation() response = view_func(request, *args, **kwargs) disable_instrumentation() if isinstance(response, TemplateResponse): # We could use ``SingleTemplateResponse`` to catch both # django and restframework responses. Unfortunately # the content_type on restframework responses is set # very late (render), while at the same time django # defaults it to text/html until then. try: response.render() except jinja2.exceptions.TemplateError as err: response = TemplateResponse( request=request, template="400.html", context={'messages': [str(err)]}, # using=view_func.template_engine, status=400) response.render() soup = _inject_edition_tools( response, request, context=get_edition_tools_context_data()) if soup: # str(soup) instead of soup.prettify() to avoid # trailing whitespace on a reformatted HTML textarea response.content = str(soup) return response
def _wrapped_view(request, *args, **kwargs): enable_instrumentation() response = view_func(request, *args, **kwargs) disable_instrumentation() if isinstance(response, TemplateResponse): # We could use ``SingleTemplateResponse`` to catch both # django and restframework responses. Unfortunately # the content_type on restframework responses is set # very late (render), while at the same time django # defaults it to text/html until then. response.render() soup = _inject_edition_tools( response, request, context=get_edition_tools_context_data()) if soup: # str(soup) instead of soup.prettify() to avoid # trailing whitespace on a reformatted HTML textarea response.content = str(soup) return response