GET
- {% for media_type in resource.emitted_media_types %}
+ {% for media_type in resource.renderted_media_types %}
{% with resource.ACCEPT_QUERY_PARAM|add:"="|add:media_type as param %}
[
{{ media_type }}]
{% endwith %}
diff --git a/djangorestframework/templates/emitter.txt b/djangorestframework/templates/renderer.txt
similarity index 100%
rename from djangorestframework/templates/emitter.txt
rename to djangorestframework/templates/renderer.txt
diff --git a/djangorestframework/tests/breadcrumbs.py b/djangorestframework/tests/breadcrumbs.py
index 724f2ff56..2f9a7e9d2 100644
--- a/djangorestframework/tests/breadcrumbs.py
+++ b/djangorestframework/tests/breadcrumbs.py
@@ -1,6 +1,6 @@
from django.conf.urls.defaults import patterns, url
from django.test import TestCase
-from djangorestframework.breadcrumbs import get_breadcrumbs
+from djangorestframework.utils.breadcrumbs import get_breadcrumbs
from djangorestframework.resource import Resource
class Root(Resource):
diff --git a/djangorestframework/tests/description.py b/djangorestframework/tests/description.py
index 3e3f7b210..d34e2d110 100644
--- a/djangorestframework/tests/description.py
+++ b/djangorestframework/tests/description.py
@@ -1,7 +1,7 @@
from django.test import TestCase
from djangorestframework.resource import Resource
-from djangorestframework.markdownwrapper import apply_markdown
-from djangorestframework.description import get_name, get_description
+from djangorestframework.compat import apply_markdown
+from djangorestframework.utils.description import get_name, get_description
# We check that docstrings get nicely un-indented.
DESCRIPTION = """an example docstring
diff --git a/djangorestframework/tests/emitters.py b/djangorestframework/tests/emitters.py
deleted file mode 100644
index 21a7eb95d..000000000
--- a/djangorestframework/tests/emitters.py
+++ /dev/null
@@ -1,76 +0,0 @@
-from django.conf.urls.defaults import patterns, url
-from django import http
-from django.test import TestCase
-from djangorestframework.compat import View
-from djangorestframework.emitters import BaseEmitter
-from djangorestframework.mixins import ResponseMixin
-from djangorestframework.response import Response
-
-DUMMYSTATUS = 200
-DUMMYCONTENT = 'dummycontent'
-
-EMITTER_A_SERIALIZER = lambda x: 'Emitter A: %s' % x
-EMITTER_B_SERIALIZER = lambda x: 'Emitter B: %s' % x
-
-class MockView(ResponseMixin, View):
- def get(self, request):
- response = Response(DUMMYSTATUS, DUMMYCONTENT)
- return self.emit(response)
-
-class EmitterA(BaseEmitter):
- media_type = 'mock/emittera'
-
- def emit(self, output, verbose=False):
- return EMITTER_A_SERIALIZER(output)
-
-class EmitterB(BaseEmitter):
- media_type = 'mock/emitterb'
-
- def emit(self, output, verbose=False):
- return EMITTER_B_SERIALIZER(output)
-
-
-urlpatterns = patterns('',
- url(r'^$', MockView.as_view(emitters=[EmitterA, EmitterB])),
-)
-
-
-class EmitterIntegrationTests(TestCase):
- """End-to-end testing of emitters using an EmitterMixin on a generic view."""
-
- urls = 'djangorestframework.tests.emitters'
-
- def test_default_emitter_serializes_content(self):
- """If the Accept header is not set the default emitter should serialize the response."""
- resp = self.client.get('/')
- self.assertEquals(resp['Content-Type'], EmitterA.media_type)
- self.assertEquals(resp.content, EMITTER_A_SERIALIZER(DUMMYCONTENT))
- self.assertEquals(resp.status_code, DUMMYSTATUS)
-
- def test_default_emitter_serializes_content_on_accept_any(self):
- """If the Accept header is set to */* the default emitter should serialize the response."""
- resp = self.client.get('/', HTTP_ACCEPT='*/*')
- self.assertEquals(resp['Content-Type'], EmitterA.media_type)
- self.assertEquals(resp.content, EMITTER_A_SERIALIZER(DUMMYCONTENT))
- self.assertEquals(resp.status_code, DUMMYSTATUS)
-
- def test_specified_emitter_serializes_content_default_case(self):
- """If the Accept header is set the specified emitter should serialize the response.
- (In this case we check that works for the default emitter)"""
- resp = self.client.get('/', HTTP_ACCEPT=EmitterA.media_type)
- self.assertEquals(resp['Content-Type'], EmitterA.media_type)
- self.assertEquals(resp.content, EMITTER_A_SERIALIZER(DUMMYCONTENT))
- self.assertEquals(resp.status_code, DUMMYSTATUS)
-
- def test_specified_emitter_serializes_content_non_default_case(self):
- """If the Accept header is set the specified emitter should serialize the response.
- (In this case we check that works for a non-default emitter)"""
- resp = self.client.get('/', HTTP_ACCEPT=EmitterB.media_type)
- self.assertEquals(resp['Content-Type'], EmitterB.media_type)
- self.assertEquals(resp.content, EMITTER_B_SERIALIZER(DUMMYCONTENT))
- self.assertEquals(resp.status_code, DUMMYSTATUS)
-
- def test_unsatisfiable_accept_header_on_request_returns_406_status(self):
- """If the Accept header is unsatisfiable we should return a 406 Not Acceptable response."""
- resp = self.client.get('/', HTTP_ACCEPT='foo/bar')
- self.assertEquals(resp.status_code, 406)
\ No newline at end of file
diff --git a/djangorestframework/tests/parsers.py b/djangorestframework/tests/parsers.py
index 4753f6f39..00ebc812b 100644
--- a/djangorestframework/tests/parsers.py
+++ b/djangorestframework/tests/parsers.py
@@ -82,7 +82,7 @@ from django.test import TestCase
from djangorestframework.compat import RequestFactory
from djangorestframework.parsers import MultipartParser
from djangorestframework.resource import Resource
-from djangorestframework.mediatypes import MediaType
+from djangorestframework.utils.mediatypes import MediaType
from StringIO import StringIO
def encode_multipart_formdata(fields, files):
diff --git a/djangorestframework/tests/renderers.py b/djangorestframework/tests/renderers.py
new file mode 100644
index 000000000..df0d9c8d4
--- /dev/null
+++ b/djangorestframework/tests/renderers.py
@@ -0,0 +1,76 @@
+from django.conf.urls.defaults import patterns, url
+from django import http
+from django.test import TestCase
+from djangorestframework.compat import View
+from djangorestframework.renderers import BaseRenderer
+from djangorestframework.mixins import ResponseMixin
+from djangorestframework.response import Response
+
+DUMMYSTATUS = 200
+DUMMYCONTENT = 'dummycontent'
+
+RENDERER_A_SERIALIZER = lambda x: 'Renderer A: %s' % x
+RENDERER_B_SERIALIZER = lambda x: 'Renderer B: %s' % x
+
+class MockView(ResponseMixin, View):
+ def get(self, request):
+ response = Response(DUMMYSTATUS, DUMMYCONTENT)
+ return self.render(response)
+
+class RendererA(BaseRenderer):
+ media_type = 'mock/renderera'
+
+ def render(self, output, verbose=False):
+ return RENDERER_A_SERIALIZER(output)
+
+class RendererB(BaseRenderer):
+ media_type = 'mock/rendererb'
+
+ def render(self, output, verbose=False):
+ return RENDERER_B_SERIALIZER(output)
+
+
+urlpatterns = patterns('',
+ url(r'^$', MockView.as_view(renderers=[RendererA, RendererB])),
+)
+
+
+class RendererIntegrationTests(TestCase):
+ """End-to-end testing of renderers using an RendererMixin on a generic view."""
+
+ urls = 'djangorestframework.tests.renderers'
+
+ def test_default_renderer_serializes_content(self):
+ """If the Accept header is not set the default renderer should serialize the response."""
+ resp = self.client.get('/')
+ self.assertEquals(resp['Content-Type'], RendererA.media_type)
+ self.assertEquals(resp.content, RENDERER_A_SERIALIZER(DUMMYCONTENT))
+ self.assertEquals(resp.status_code, DUMMYSTATUS)
+
+ def test_default_renderer_serializes_content_on_accept_any(self):
+ """If the Accept header is set to */* the default renderer should serialize the response."""
+ resp = self.client.get('/', HTTP_ACCEPT='*/*')
+ self.assertEquals(resp['Content-Type'], RendererA.media_type)
+ self.assertEquals(resp.content, RENDERER_A_SERIALIZER(DUMMYCONTENT))
+ self.assertEquals(resp.status_code, DUMMYSTATUS)
+
+ def test_specified_renderer_serializes_content_default_case(self):
+ """If the Accept header is set the specified renderer should serialize the response.
+ (In this case we check that works for the default renderer)"""
+ resp = self.client.get('/', HTTP_ACCEPT=RendererA.media_type)
+ self.assertEquals(resp['Content-Type'], RendererA.media_type)
+ self.assertEquals(resp.content, RENDERER_A_SERIALIZER(DUMMYCONTENT))
+ self.assertEquals(resp.status_code, DUMMYSTATUS)
+
+ def test_specified_renderer_serializes_content_non_default_case(self):
+ """If the Accept header is set the specified renderer should serialize the response.
+ (In this case we check that works for a non-default renderer)"""
+ resp = self.client.get('/', HTTP_ACCEPT=RendererB.media_type)
+ self.assertEquals(resp['Content-Type'], RendererB.media_type)
+ self.assertEquals(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
+ self.assertEquals(resp.status_code, DUMMYSTATUS)
+
+ def test_unsatisfiable_accept_header_on_request_returns_406_status(self):
+ """If the Accept header is unsatisfiable we should return a 406 Not Acceptable response."""
+ resp = self.client.get('/', HTTP_ACCEPT='foo/bar')
+ self.assertEquals(resp.status_code, 406)
\ No newline at end of file
diff --git a/djangorestframework/utils.py b/djangorestframework/utils/__init__.py
similarity index 98%
rename from djangorestframework/utils.py
rename to djangorestframework/utils/__init__.py
index f60bdee4d..9dc769be2 100644
--- a/djangorestframework/utils.py
+++ b/djangorestframework/utils/__init__.py
@@ -1,13 +1,12 @@
-import re
-import xml.etree.ElementTree as ET
from django.utils.encoding import smart_unicode
from django.utils.xmlutils import SimplerXMLGenerator
from django.core.urlresolvers import resolve
from django.conf import settings
-try:
- import cStringIO as StringIO
-except ImportError:
- import StringIO
+
+from djangorestframework.compat import StringIO
+
+import re
+import xml.etree.ElementTree as ET
#def admin_media_prefix(request):
diff --git a/djangorestframework/breadcrumbs.py b/djangorestframework/utils/breadcrumbs.py
similarity index 90%
rename from djangorestframework/breadcrumbs.py
rename to djangorestframework/utils/breadcrumbs.py
index ba779dd01..1e604efce 100644
--- a/djangorestframework/breadcrumbs.py
+++ b/djangorestframework/utils/breadcrumbs.py
@@ -1,5 +1,5 @@
from django.core.urlresolvers import resolve
-from djangorestframework.description import get_name
+from djangorestframework.utils.description import get_name
def get_breadcrumbs(url):
"""Given a url returns a list of breadcrumbs, which are each a tuple of (name, url)."""
@@ -7,7 +7,6 @@ def get_breadcrumbs(url):
def breadcrumbs_recursive(url, breadcrumbs_list):
"""Add tuples of (name, url) to the breadcrumbs list, progressively chomping off parts of the url."""
- # This is just like compsci 101 all over again...
try:
(view, unused_args, unused_kwargs) = resolve(url)
except:
diff --git a/djangorestframework/description.py b/djangorestframework/utils/description.py
similarity index 100%
rename from djangorestframework/description.py
rename to djangorestframework/utils/description.py
diff --git a/djangorestframework/mediatypes.py b/djangorestframework/utils/mediatypes.py
similarity index 100%
rename from djangorestframework/mediatypes.py
rename to djangorestframework/utils/mediatypes.py