diff --git a/aircox/middleware.py b/aircox/middleware.py index 3382ee4..8b5cbb1 100644 --- a/aircox/middleware.py +++ b/aircox/middleware.py @@ -13,6 +13,7 @@ class AircoxMiddleware(object): """Middleware used to get default info for the given website. It provide following request attributes: + - ``mobile``: set to True if mobile device is detected - ``station``: current Station This middleware must be set after the middleware @@ -24,6 +25,11 @@ class AircoxMiddleware(object): def __init__(self, get_response): self.get_response = get_response + def is_mobile(self, request): + if agent := request.META.get("HTTP_USER_AGENT"): + return " Mobi" in agent + return False + def get_station(self, request): """Return station for the provided request.""" host = request.get_host() @@ -45,6 +51,7 @@ class AircoxMiddleware(object): def __call__(self, request): self.init_timezone(request) request.station = self.get_station(request) + request.is_mobile = self.is_mobile(request) try: return self.get_response(request) except Redirect: diff --git a/aircox/templates/aircox/base.html b/aircox/templates/aircox/base.html index 71bd1a7..dcd44b4 100644 --- a/aircox/templates/aircox/base.html +++ b/aircox/templates/aircox/base.html @@ -40,7 +40,7 @@ Usefull context: {% block head_extra %}{% endblock %} - +