put is_mobile and is_tablet in the result of user_agent()

This commit is contained in:
Leonel Câmara
2017-08-08 00:50:55 +01:00
parent 0b41ed36f9
commit 8533fa0d00
2 changed files with 10 additions and 2 deletions
+3
View File
@@ -678,6 +678,9 @@ def simple_detect(agent):
class mobilize(object):
"""
Decorator for controller functions so they use different views for mobile devices.
WARNING: If you update httpagentparser make sure to leave mobilize for
backwards compatibility.
"""
def __init__(self, func):
self.func = func
+7 -2
View File
@@ -331,11 +331,16 @@ class Request(Storage):
user_agent = session._user_agent
if user_agent:
return user_agent
user_agent = user_agent_parser.detect(self.env.http_user_agent)
http_user_agent = self.env.http_user_agent
user_agent = user_agent_parser.detect(http_user_agent)
for key, value in user_agent.items():
if isinstance(value, dict):
user_agent[key] = Storage(value)
user_agent = session._user_agent = Storage(user_agent)
user_agent = Storage(user_agent)
user_agent.is_mobile = 'Mobile' in http_user_agent
user_agent.is_tablet = 'Tablet' in http_user_agent
session._user_agent = user_agent
return user_agent
def requires_https(self):