Skip to content

Commit

Permalink
Make login button label configurable (#275)
Browse files Browse the repository at this point in the history
* Let login button label configurable

* More logs

* Mistake logging syntax with other libs

* Fix coding style
  • Loading branch information
hongquan authored Feb 20, 2025
1 parent 2ca2edf commit dbeccc0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ screens/
# Stuff which were generated by our Docker containers
.bash_history
.npm
.python_history
6 changes: 4 additions & 2 deletions src/pretalx.example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ static = /var/pretalx/static
debug = False
url = https://eventyay.mydomain.com
name = eventyay
# To select a variant from CALL_FOR_SPEAKER_LOGIN_BTN_LABELS.
call_for_speaker_login_button_label = default

[database]
backend = postgresql
name = pretalx
user = pretalx
# For PostgreSQL on the same host, we don't need one because we can use
# peer authentification if our PostgreSQL user matches our unix user.
password = Change this in production or you're going to have a bad time
password = Change this in production or you"'"re going to have a bad time
# For a remote host, supply an IP address
# For local postgres authentication, you can leave the host empty
host = localhost
Expand All @@ -27,6 +29,6 @@ from = admin@localhost
host = localhost
port = 25
user = admin
password = Change this in production or you're going to have a bad time
password = Change this in production or you"'"re going to have a bad time
tls = False
ssl = True
19 changes: 18 additions & 1 deletion src/pretalx/cfp/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
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 @@ -25,7 +27,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 phrases
from pretalx.common.text.phrases import CALL_FOR_SPEAKER_LOGIN_BTN_LABELS, phrases
from pretalx.person.forms import SpeakerProfileForm, UserForm
from pretalx.person.models import User
from pretalx.submission.forms import InfoForm, QuestionsForm
Expand All @@ -36,6 +38,8 @@
Track,
)

logger = logging.getLogger(__name__)


def i18n_string(data, locales):
if isinstance(data, LazyI18nString):
Expand Down Expand Up @@ -182,6 +186,19 @@ 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
1 change: 1 addition & 0 deletions src/pretalx/common/phrases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
_phrase_book = {}


# TODO: It seems to be superseded by the pretalx.common.text.phrases module.
class PhrasesMetaClass(ABCMeta): # noqa
def __new__(cls, class_name, bases, namespace, app):
new = super().__new__(cls, class_name, bases, namespace)
Expand Down
26 changes: 20 additions & 6 deletions src/pretalx/common/settings/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import configparser
import logging
import os
import sys
from configparser import RawConfigParser
from pathlib import Path

logger = logging.getLogger(__name__)


CONFIG = {
"filesystem": {
"base": {
Expand Down Expand Up @@ -157,10 +162,19 @@
}


def read_config_files(config):
if "PRETALX_CONFIG_FILE" in os.environ:
with open(os.environ.get("PRETALX_CONFIG_FILE"), encoding="utf-8") as fp:
config_files = config.read_file(fp)
def read_config_files(config: RawConfigParser) -> tuple[RawConfigParser, list[str]]:
if path_from_env := os.getenv("PRETALX_CONFIG_FILE"):
file_path = Path(path_from_env)
if file_path.exists():
with file_path.open(encoding="utf-8") as fp:
config.read_file(fp)
config_files = [str(file_path.resolve())]
else:
logger.warning(
"File specified by PRETALX_CONFIG_FILE does not exist. %s",
path_from_env,
)
config_files = []
else:
config_files = config.read(
[
Expand All @@ -185,7 +199,7 @@ def reduce_dict(data):
}


def read_layer(layer_name, config):
def read_layer(layer_name: str, config: RawConfigParser) -> RawConfigParser:
config_dict = reduce_dict(
{
section_name: {
Expand All @@ -198,7 +212,7 @@ def read_layer(layer_name, config):
return config


def build_config():
def build_config() -> tuple[RawConfigParser, list[str]]:
config = configparser.RawConfigParser()
config = read_layer("default", config)
config, config_files = read_config_files(config)
Expand Down
2 changes: 1 addition & 1 deletion src/pretalx/common/templates/common/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div class="panel panel-default">
<div class="panel-heading text-center" id="headingOne">
<a class="btn btn-lg btn-primary btn-block mt-3" href="{% oauth_login_url next_url %}">
{{ _('Login') }}
{{ login_button_label }}
</a>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/pretalx/common/text/phrases.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(cls, *args, app, **kwargs):
super().__init__(*args, **kwargs)


# TODO: This utility seems to be for caching text. If so, we should use https://pypi.org/project/moka-py/
# to have proper type support.
class Phrases(metaclass=PhrasesMetaClass, app=""):
def __getattribute__(self, attribute):
result = super().__getattribute__(attribute)
Expand Down Expand Up @@ -102,3 +104,10 @@ class BasePhrases(Phrases, app="base"):
general = _("General")
email_subject = pgettext_lazy("email subject", "Subject")
text_body = _("Text")


# We want to show different button label depending on deployment site.
CALL_FOR_SPEAKER_LOGIN_BTN_LABELS = {
"default": _("Login"),
"mediawiki": _("Login with MediaWiki SSO or Email"),
}

0 comments on commit dbeccc0

Please sign in to comment.