code quality

This commit is contained in:
bkfox
2023-03-13 17:47:00 +01:00
parent 934817da8a
commit 112770eddf
162 changed files with 4798 additions and 4069 deletions

View File

@ -5,13 +5,13 @@ from django.utils import timezone as tz
from .models import Station
from .utils import Redirect
__all__ = ['AircoxMiddleware']
__all__ = ("AircoxMiddleware",)
class AircoxMiddleware(object):
"""
Middleware used to get default info for the given website. Theses
"""Middleware used to get default info for the given website.
Theses
This middleware must be set after the middleware
'django.contrib.auth.middleware.AuthenticationMiddleware',
"""
@ -20,11 +20,11 @@ class AircoxMiddleware(object):
self.get_response = get_response
def get_station(self, request):
""" Return station for the provided request """
"""Return station for the provided request."""
expr = Q(default=True) | Q(hosts__contains=request.get_host())
# case = Case(When(hosts__contains=request.get_host(), then=Value(0)),
# When(default=True, then=Value(32)))
return Station.objects.filter(expr).order_by('default').first()
return Station.objects.filter(expr).order_by("default").first()
# .annotate(resolve_priority=case) \
# .order_by('resolve_priority').first()
@ -33,10 +33,10 @@ class AircoxMiddleware(object):
# required
timezone = None
try:
timezone = request.session.get('aircox.timezone')
timezone = request.session.get("aircox.timezone")
if timezone:
timezone = pytz.timezone(timezone)
except:
except Exception:
pass
if not timezone: