From 9db69580e021faacf1b3f8ac16bc4c6c73789045 Mon Sep 17 00:00:00 2001 From: Christophe Siraut Date: Mon, 13 Nov 2023 13:41:16 +0100 Subject: [PATCH] misc: move station and audio_streams to context_processors (in order to have them available in accounts views) --- aircox/context_processors/__init__.py | 3 +++ aircox/views/base.py | 4 ---- instance/settings/base.py | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 aircox/context_processors/__init__.py diff --git a/aircox/context_processors/__init__.py b/aircox/context_processors/__init__.py new file mode 100644 index 0000000..e79119a --- /dev/null +++ b/aircox/context_processors/__init__.py @@ -0,0 +1,3 @@ +def station(request): + station = request.station + return {"station": station, "audio_streams": station.streams} diff --git a/aircox/views/base.py b/aircox/views/base.py index 0cb115a..bb22402 100644 --- a/aircox/views/base.py +++ b/aircox/views/base.py @@ -50,13 +50,9 @@ class BaseView(TemplateResponseMixin, ContextMixin): return None def get_context_data(self, **kwargs): - kwargs.setdefault("station", self.station) kwargs.setdefault("page", self.get_page()) kwargs.setdefault("header_template_name", self.header_template_name) - if "audio_streams" not in kwargs: - kwargs["audio_streams"] = self.station.streams - if "model" not in kwargs: model = getattr(self, "model", None) or hasattr(self, "object") and type(self.object) kwargs["model"] = model diff --git a/instance/settings/base.py b/instance/settings/base.py index 30b5a6a..2f7053c 100755 --- a/instance/settings/base.py +++ b/instance/settings/base.py @@ -238,6 +238,7 @@ TEMPLATES = [ "django.template.context_processors.static", "django.template.context_processors.tz", "django.contrib.messages.context_processors.messages", + "aircox.context_processors.station", ), "loaders": ( "django.template.loaders.filesystem.Loader",