Skip to content

Commit

Permalink
Fix: Login button label is missing (#277)
Browse files Browse the repository at this point in the history
* Fix: Login button label is missing

Many pages share a common button template, so we need to compute it from context processors.

* Shorter code

* Fix coding style

* Fix logic after changing per sourcery-ai suggestion
  • Loading branch information
hongquan authored Feb 21, 2025
1 parent dbeccc0 commit e50dc2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
17 changes: 1 addition & 16 deletions src/pretalx/cfp/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 18 additions & 2 deletions src/pretalx/orga/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
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):
Expand All @@ -23,12 +29,22 @@ 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
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)
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
Expand Down

0 comments on commit e50dc2f

Please sign in to comment.