detect mobileclient

This commit is contained in:
Laura Klünder 2018-12-17 00:05:40 +01:00
parent 9c478bb6f7
commit 61967b0e4e

View file

@ -5,6 +5,30 @@ class MobileclientMiddleware:
def __init__(self, get_response):
self.get_response = get_response
@staticmethod
def is_mobileclient(request):
if 'fakemobileclient' in request.GET:
return True
user_agent = request.META.get('HTTP_USER_AGENT', '')
if not user_agent.startswith('c3navClient/'):
return False
user_agent = user_agent[12:].split('/')
if len(user_agent) != 2:
return False
app_platform, app_version = user_agent
if app_platform == 'Android':
# activate new mobileclient features for the c3nav android app 4.0.0 or higher
# yep, iphone app can do this stuff yet
if not app_version.isdigit():
return False
app_version = int(app_version)
return app_version >= 14040000
return False
def __call__(self, request):
request.mobileclient = 'c3navclient' in request.META['HTTP_USER_AGENT'] or 'fakemobileclient' in request.GET
request.mobileclient = self.is_mobileclient(request)
return self.get_response(request)