From 98362054c6bdf434610e0531ab12d0d8f30abc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Fri, 21 Feb 2025 10:43:33 +0700 Subject: [PATCH 1/4] Fix: Login button label is missing Many pages share a common button template, so we need to compute it from context processors. --- src/pretalx/cfp/flow.py | 17 +---------------- src/pretalx/orga/context_processors.py | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/pretalx/cfp/flow.py b/src/pretalx/cfp/flow.py index 9869533a6..3b2e7ced9 100644 --- a/src/pretalx/cfp/flow.py +++ b/src/pretalx/cfp/flow.py @@ -2,10 +2,8 @@ import json import logging from collections import OrderedDict -from configparser import RawConfigParser from contextlib import suppress from pathlib import Path -from typing import cast from django.conf import settings from django.contrib import messages @@ -27,7 +25,7 @@ from pretalx.cfp.signals import cfp_steps from pretalx.common.exceptions import SendMailException from pretalx.common.language import language -from pretalx.common.text.phrases import CALL_FOR_SPEAKER_LOGIN_BTN_LABELS, phrases +from pretalx.common.text.phrases import phrases from pretalx.person.forms import SpeakerProfileForm, UserForm from pretalx.person.models import User from pretalx.submission.forms import InfoForm, QuestionsForm @@ -186,19 +184,6 @@ def get_context_data(self, **kwargs): if step.is_applicable(self.request) ], ) - # Select label for login button - config = cast(RawConfigParser, settings.CONFIG) - try: - key = config["site"]["call_for_speaker_login_button_label"] - except KeyError: - # TODO: The logs cannot be observed with the development Docker setup. Should be fixed. - logger.info("Config file misses `call_for_speaker_login_button_label` key!") - key = "default" - try: - button_label = CALL_FOR_SPEAKER_LOGIN_BTN_LABELS[key] - except KeyError: - button_label = CALL_FOR_SPEAKER_LOGIN_BTN_LABELS["default"] - kwargs.setdefault("login_button_label", button_label) return kwargs def render(self, **kwargs): diff --git a/src/pretalx/orga/context_processors.py b/src/pretalx/orga/context_processors.py index 1ccc32114..9f9e16714 100644 --- a/src/pretalx/orga/context_processors.py +++ b/src/pretalx/orga/context_processors.py @@ -1,9 +1,17 @@ +import logging +from configparser import RawConfigParser +from typing import cast + from django.conf import settings from django.utils.module_loading import import_string + +from pretalx.common.text.phrases import CALL_FOR_SPEAKER_LOGIN_BTN_LABELS from pretalx.orga.signals import html_head, nav_event, nav_event_settings, nav_global + SessionStore = import_string(f"{settings.SESSION_ENGINE}.SessionStore") +logger = logging.getLogger(__name__) def collect_signal(signal, kwargs): @@ -23,12 +31,26 @@ def orga_events(request): # Extract site specific values from settings.CONFIG.items('site') and add them to the context # This is a bit of a hack, but it's the only way to get the site specific values into the context # rather than using the settings object directly in the template - site_config = dict(settings.CONFIG.items("site")) + config = cast(RawConfigParser, settings.CONFIG) + site_config = dict(config.items("site")) context["site_config"] = site_config context["base_path"] = settings.BASE_PATH + # Login button label + try: + key = site_config["call_for_speaker_login_button_label"] + except KeyError: + key = "default" + try: + button_label = CALL_FOR_SPEAKER_LOGIN_BTN_LABELS[key] + except KeyError: + logger.warning("%s does not exist in CALL_FOR_SPEAKER_LOGIN_BTN_LABELS", key) + button_label = CALL_FOR_SPEAKER_LOGIN_BTN_LABELS["default"] + context["login_button_label"] = button_label if not request.path_info.startswith("/orga/"): - return {} + return { + "login_button_label": button_label, + } if not getattr(request, "user", None) or not request.user.is_authenticated: return context From d07e9b8e9c9ff223a0aa405ea2dadce99e3d3650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Fri, 21 Feb 2025 10:51:22 +0700 Subject: [PATCH 2/4] Shorter code --- src/pretalx/orga/context_processors.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pretalx/orga/context_processors.py b/src/pretalx/orga/context_processors.py index 9f9e16714..8edc65c1e 100644 --- a/src/pretalx/orga/context_processors.py +++ b/src/pretalx/orga/context_processors.py @@ -36,13 +36,9 @@ def orga_events(request): context["site_config"] = site_config context["base_path"] = settings.BASE_PATH # Login button label - try: - key = site_config["call_for_speaker_login_button_label"] - except KeyError: - key = "default" - try: - button_label = CALL_FOR_SPEAKER_LOGIN_BTN_LABELS[key] - except KeyError: + key = site_config.get("login_button_label", "default") + button_label = CALL_FOR_SPEAKER_LOGIN_BTN_LABELS.get(key) + if not button_label: logger.warning("%s does not exist in CALL_FOR_SPEAKER_LOGIN_BTN_LABELS", key) button_label = CALL_FOR_SPEAKER_LOGIN_BTN_LABELS["default"] context["login_button_label"] = button_label From 95d78274f9007e6af5b7f9cf69c149509aa69207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Fri, 21 Feb 2025 10:55:36 +0700 Subject: [PATCH 3/4] Fix coding style --- src/pretalx/orga/context_processors.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pretalx/orga/context_processors.py b/src/pretalx/orga/context_processors.py index 8edc65c1e..a71a7c151 100644 --- a/src/pretalx/orga/context_processors.py +++ b/src/pretalx/orga/context_processors.py @@ -5,11 +5,9 @@ from django.conf import settings from django.utils.module_loading import import_string - from pretalx.common.text.phrases import CALL_FOR_SPEAKER_LOGIN_BTN_LABELS from pretalx.orga.signals import html_head, nav_event, nav_event_settings, nav_global - SessionStore = import_string(f"{settings.SESSION_ENGINE}.SessionStore") logger = logging.getLogger(__name__) From 1e7400996c4490bd9a11ad99916ccd701f33440a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Fri, 21 Feb 2025 11:00:32 +0700 Subject: [PATCH 4/4] Fix logic after changing per sourcery-ai suggestion --- src/pretalx/orga/context_processors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pretalx/orga/context_processors.py b/src/pretalx/orga/context_processors.py index a71a7c151..daa8f7192 100644 --- a/src/pretalx/orga/context_processors.py +++ b/src/pretalx/orga/context_processors.py @@ -34,7 +34,7 @@ def orga_events(request): context["site_config"] = site_config context["base_path"] = settings.BASE_PATH # Login button label - key = site_config.get("login_button_label", "default") + key = site_config.get("call_for_speaker_login_button_label", "default") button_label = CALL_FOR_SPEAKER_LOGIN_BTN_LABELS.get(key) if not button_label: logger.warning("%s does not exist in CALL_FOR_SPEAKER_LOGIN_BTN_LABELS", key)