#132 | #121: backoffice / dev-1.0-121 (#131)

cfr #121

Co-authored-by: Christophe Siraut <d@tobald.eu.org>
Co-authored-by: bkfox <thomas bkfox net>
Co-authored-by: Thomas Kairos <thomas@bkfox.net>
Reviewed-on: rc/aircox#131
Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
This commit is contained in:
2024-04-28 22:02:09 +02:00
committed by Thomas Kairos
parent 1e17a1334a
commit 55123c386d
348 changed files with 124397 additions and 17879 deletions

View File

@ -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: