Created
February 17, 2012 00:45
-
-
Save smcoll/1849267 to your computer and use it in GitHub Desktop.
more flexible DocumentingTemplateRenderer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DocumentingTemplateRenderer: | |
... | |
escape_binary = False | |
def _escape_binary(self, content): | |
if self.escape_binary and not all(char in string.printable for char in content): | |
return '[%d bytes of binary content]' % len(content) | |
return content | |
def _get_content(self, view, request, obj, media_type): | |
renderers = [renderer for renderer in view.renderers if not issubclass(renderer, DocumentingTemplateRenderer)] | |
if not renderers: | |
return '[No renderers were found]' | |
media_type = add_media_type_param(media_type, 'indent', '4') | |
content = renderers[0](view).render(obj, media_type) | |
return self._escape_binary(content) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment