Skip to content

Commit

Permalink
Pyramid 1.1 API compliance - use request.response.content_type
Browse files Browse the repository at this point in the history
  • Loading branch information
elemoine committed Jun 27, 2011
1 parent e01d123 commit 4ea3290
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions papyrus/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ def _render(value, system):
ret = geojson.dumps(value, cls=Encoder, use_decimal=True)
request = system.get('request')
if request is not None:
if not hasattr(request, 'response_content_type'):
response = request.response
ct = response.content_type
if ct == response.default_content_type:
callback = request.params.get('callback')
if callback is None:
request.response_content_type = 'application/json'
response.content_type = 'application/json'
else:
request.response_content_type = 'text/javascript'
response.content_type = 'text/javascript'
ret = '%(callback)s(%(json)s);' % {'callback': callback,
'json': ret}
return ret
Expand Down
14 changes: 7 additions & 7 deletions papyrus/tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_geojson(self):
request = testing.DummyRequest()
result = renderer(f, {'request': request})
self.assertEqual(result, '{"geometry": {"type": "Point", "coordinates": [53, -4]}, "type": "Feature", "properties": {"title": "Dict 1"}, "id": 1}')
self.assertEqual(request.response_content_type, 'application/json')
self.assertEqual(request.response.content_type, 'application/json')

def test_geojson_content_type(self):
renderer = self._callFUT(None)
Expand All @@ -34,10 +34,10 @@ def test_geojson_content_type(self):
'properties': {'title': 'Dict 1'},
}
request = testing.DummyRequest()
request.response_content_type = 'text/javascript'
request.response.content_type = 'text/javascript'
result = renderer(f, {'request': request})
self.assertEqual(result, '{"geometry": {"type": "Point", "coordinates": [53, -4]}, "type": "Feature", "properties": {"title": "Dict 1"}, "id": 1}')
self.assertEqual(request.response_content_type, 'text/javascript')
self.assertEqual(request.response.content_type, 'text/javascript')

def test_Decimal(self):
renderer = self._callFUT(None)
Expand All @@ -51,7 +51,7 @@ def test_Decimal(self):
request = testing.DummyRequest()
result = renderer(f, {'request': request})
self.assertEqual(result, '{"geometry": {"type": "Point", "coordinates": [53, -4]}, "type": "Feature", "properties": {"decimal": 0.003}, "id": 1}')
self.assertEqual(request.response_content_type, 'application/json')
self.assertEqual(request.response.content_type, 'application/json')

def test_date(self):
renderer = self._callFUT(None)
Expand All @@ -65,7 +65,7 @@ def test_date(self):
request = testing.DummyRequest()
result = renderer(f, {'request': request})
self.assertEqual(result, '{"geometry": {"type": "Point", "coordinates": [53, -4]}, "type": "Feature", "properties": {"date": "2011-05-21"}, "id": 1}')
self.assertEqual(request.response_content_type, 'application/json')
self.assertEqual(request.response.content_type, 'application/json')

def test_datetime(self):
renderer = self._callFUT(None)
Expand All @@ -79,7 +79,7 @@ def test_datetime(self):
request = testing.DummyRequest()
result = renderer(f, {'request': request})
self.assertEqual(result, '{"geometry": {"type": "Point", "coordinates": [53, -4]}, "type": "Feature", "properties": {"datetime": "2011-05-21T20:55:12"}, "id": 1}')
self.assertEqual(request.response_content_type, 'application/json')
self.assertEqual(request.response.content_type, 'application/json')


def test_geojsonp(self):
Expand All @@ -94,4 +94,4 @@ def test_geojsonp(self):
request.params['callback'] = 'jsonp_cb'
result = renderer(f, {'request': request})
self.assertEqual(result, 'jsonp_cb({"geometry": {"type": "Point", "coordinates": [53, -4]}, "type": "Feature", "properties": {"title": "Dict 1"}, "id": 1});')
self.assertEqual(request.response_content_type, 'text/javascript')
self.assertEqual(request.response.content_type, 'text/javascript')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
CHANGES = open(os.path.join(here, 'CHANGES.rst')).read()

install_requires = [
'pyramid>=1.0',
'pyramid>=1.1a3',
'geojson>=1.0',
'Shapely>=1.2',
'GeoAlchemy>=0.5'
Expand Down

0 comments on commit 4ea3290

Please sign in to comment.