Skip to content

Commit

Permalink
use middelware instead of hardcoded locale
Browse files Browse the repository at this point in the history
  • Loading branch information
kritzl committed Mar 31, 2024
1 parent f5d374e commit 3d72d03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions mafiasi/base/special_day_middleware.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion mafiasi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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",
]

Expand Down

0 comments on commit 3d72d03

Please sign in to comment.