From 3d72d03a843c96f335fca7133a6ac9fb4d9d0e83 Mon Sep 17 00:00:00 2001 From: kritzl Date: Mon, 1 Apr 2024 00:29:02 +0200 Subject: [PATCH] use middelware instead of hardcoded locale --- mafiasi/base/special_day_middleware.py | 21 +++++++++++++++++++++ mafiasi/settings.py | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 mafiasi/base/special_day_middleware.py diff --git a/mafiasi/base/special_day_middleware.py b/mafiasi/base/special_day_middleware.py new file mode 100644 index 0000000..5e4e09f --- /dev/null +++ b/mafiasi/base/special_day_middleware.py @@ -0,0 +1,21 @@ +from django.utils import translation +from django.utils.timezone import now, localdate, get_current_timezone + + +class SpecialDayMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + # get date in current timezone + n = localdate(now(), get_current_timezone()) + + # first of april (april fools) + if n.day == 1 and n.month == 4: + translation.activate('en-uwu') + request.LANGUAGE_CODE = translation.get_language() + + # call view + response = self.get_response(request) + + return response diff --git a/mafiasi/settings.py b/mafiasi/settings.py index 63aed94..aeec7ca 100644 --- a/mafiasi/settings.py +++ b/mafiasi/settings.py @@ -101,7 +101,7 @@ USE_L10N = True USE_TZ = True TIME_ZONE = "Europe/Berlin" -LANGUAGE_CODE = "en-uwu" +LANGUAGE_CODE = "en-us" SECRET_KEY = env.str("MAFIASI_SECRET_KEY") @@ -126,6 +126,7 @@ # Uncomment the next line for simple clickjacking protection: # 'django.middleware.clickjacking.XFrameOptionsMiddleware', "mafiasi.base.middleware.InvalidMailMiddleware", + "mafiasi.base.special_day_middleware.SpecialDayMiddleware", "simple_openid_connect.integrations.django.middleware.TokenVerificationMiddleware", ]