Skip to content

Commit

Permalink
Merge pull request #1 from tino/master
Browse files Browse the repository at this point in the history
Allow for floating pixelratios. (Happens when people use browser zoom)
  • Loading branch information
svleeuwen committed May 21, 2014
2 parents a63e694 + 02cc98d commit 51129d9
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 51129d9

Please sign in to comment.