コード例 #1
0
 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
コード例 #2
0
ファイル: mixins.py プロジェクト: rahulyhg/djaoapp
    def add_edition_tools(self, response, context=None):
        """
        If the ``request.user`` has editable permissions, this method
        injects the edition tools into the html *content* and return
        a BeautifulSoup object of the resulting content + tools.

        If the response is editable according to the proxy rules, this
        method returns a BeautifulSoup object of the content such that
        ``PageMixin`` inserts the edited page elements.
        """
        if context is None:
            context = {}
        context.update(get_edition_tools_context_data())
        return inject_edition_tools(
            response, request=self.request, context=context)
コード例 #3
0
ファイル: decorators.py プロジェクト: dwino92/djaoapp
 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