diff options
| author | tom christie tom@tomchristie.com | 2011-01-23 23:08:44 +0000 |
|---|---|---|
| committer | tom christie tom@tomchristie.com | 2011-01-23 23:08:44 +0000 |
| commit | e95198a1c0b206bd3b565bb62d167ada71595099 (patch) | |
| tree | 65dc7f469b28f09783b732862ab9822b8528f10d /src/rest/emitters.py | |
| parent | 4100242fa2395bef8db0c5ffbab6f5d0cf95301d (diff) | |
| download | django-rest-framework-e95198a1c0b206bd3b565bb62d167ada71595099.tar.bz2 | |
Sphinx docs, examples, lots of refactoring
Diffstat (limited to 'src/rest/emitters.py')
| -rw-r--r-- | src/rest/emitters.py | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/src/rest/emitters.py b/src/rest/emitters.py deleted file mode 100644 index c1ff5cc2..00000000 --- a/src/rest/emitters.py +++ /dev/null @@ -1,59 +0,0 @@ -from django.template import RequestContext, loader -import json -from utils import dict2xml - -class BaseEmitter(object): - uses_forms = False - - def __init__(self, resource): - self.resource = resource - - def emit(self, output): - return output - -class TemplatedEmitter(BaseEmitter): - template = None - - def emit(self, output): - if output is None: - content = '' - else: - content = json.dumps(output, indent=4, sort_keys=True) - - template = loader.get_template(self.template) - context = RequestContext(self.resource.request, { - 'content': content, - 'resource': self.resource, - }) - - ret = template.render(context) - - # Munge DELETE Response code to allow us to return content - # (Do this *after* we've rendered the template so that we include the normal deletion response code in the output) - if self.resource.resp_status == 204: - self.resource.resp_status = 200 - - return ret - -class JSONEmitter(BaseEmitter): - def emit(self, output): - if output is None: - # Treat None as no message body, rather than serializing - return '' - return json.dumps(output) - -class XMLEmitter(BaseEmitter): - def emit(self, output): - if output is None: - # Treat None as no message body, rather than serializing - return '' - return dict2xml(output) - -class HTMLEmitter(TemplatedEmitter): - template = 'emitter.html' - uses_forms = True - -class TextEmitter(TemplatedEmitter): - template = 'emitter.txt' - - |
