Skip to content

Commit

Permalink
Allow for floating pixelratios. (Happens when people use browser zoom)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tino de Bruijn committed May 21, 2014
1 parent a63e694 commit 02cc98d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions responsive/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def process_request(self, request):
if value is not None:
try:
width, height, pixelratio = value.split(':')
width, height, pixelratio = int(width), int(height), int(pixelratio)
width, height, pixelratio = int(width), int(height), float(pixelratio)
except ValueError:
# TODO: Add logging
width = None
height = None
pixelratio = None
info = {'width': width, 'height': height, 'pixelratio': pixelratio}
if width is not None:
info['type'] = _get_device_type(width)
info['type'] = _get_device_type(width)
else:
info['type'] = None
request.device_info = info
Expand Down
13 changes: 13 additions & 0 deletions responsive/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ def test_process_request_valid_cookie(self):
self.assertEqual(device['type'], 'phone')
self.assertEqual(device['pixelratio'], 2)

def test_process_request_float_pixelratio(self):
"""
`pixelratio` can be a float when the user uses in-browser zoom and
should give us valid device info.
"""
self.request.COOKIES['resolution'] = '1920:1200:1.100000023841858' # 110%
self.middleware.process_request(request=self.request)
device = self.request.device_info
self.assertEqual(device['width'], 1920)
self.assertEqual(device['height'], 1200)
self.assertEqual(device['type'], 'desktop')
self.assertEqual(device['pixelratio'], 1.100000023841858)


class DeviceInfoScriptTestCase(unittest.TestCase):
"Middleware for including necessary script tags in HTML responses."
Expand Down

0 comments on commit 02cc98d

Please sign in to comment.