def _wrapped_view(request, *args, **kwargs): enable_instrumentation() response = view_func(request, *args, **kwargs) disable_instrumentation() if isinstance(response, SimpleTemplateResponse): # 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 = SimpleTemplateResponse( template="400.html", context={'messages': [str(err)]}, 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 process_template_response(self, string_template, user=None): request = HttpRequest() request.user = user context = Context({'request': request}) template = BackendTemplate(Template(string_template).render(context)) response = SimpleTemplateResponse(template, context) response.content = string_template mw = ToolbarMiddleware() return mw.process_response(request, response).render()
def process_template_response(self, string_template, user=None): request = HttpRequest() request.user = user context = Context({'request': request}) template = BackendTemplate(Template(string_template).render(context)) response = SimpleTemplateResponse(template, context) response.content = string_template mw = ToolbarMiddleware() return mw.process_response(request, response).render()
def process_template_response(self, string_template): settings.TOOLBAR_INSTANT_UPDATE = False request = HttpRequest() context = Context({'request': request}) node = Template(string_template).render(context) template = BackendTemplate(node) response = SimpleTemplateResponse(template, context) response.content = node mw = TextMiddleware() return mw.process_response(request, response).render()
def process_template_response(self, string_template): settings.TOOLBAR_INSTANT_UPDATE = False request = HttpRequest() context = Context({'request': request}) node = Template(string_template).render(context) template = BackendTemplate(node) response = SimpleTemplateResponse(template, context) response.content = node mw = TextMiddleware() return mw.process_response(request, response).render()
def process_template_response(self, name, default=''): settings.TOOLBAR_INSTANT_UPDATE = False request = HttpRequest() context = Context({'request': request}) node = Template( '{%% load text %%}{%% text "%s" "%s" %%}' % (name, default)).render(context) template = BackendTemplate(node) response = SimpleTemplateResponse(template, context) response.content = node mw = TextMiddleware() return mw.process_template_response(request, response).render()