Features: 1) None;

Fixes: 1) Remove unused `GrapheneLocaleMiddleware` and `CustomLocaleCommonMiddleware` from middleware stack; 2) Remove unused `get_language_from_header` import and related translation logic;

Extra: 1) Clean up settings and middleware files by removing redundant locale handling logic; 2) Minor formatting adjustments for consistency.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-05-20 21:06:20 +03:00
parent b18c75ccd2
commit 9d7efa310a
3 changed files with 0 additions and 26 deletions

View file

@ -8,13 +8,10 @@ from django.core.exceptions import DisallowedHost
from django.http import HttpResponseForbidden
from django.middleware.common import CommonMiddleware
from django.shortcuts import redirect
from django.utils import translation
from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework_simplejwt.exceptions import InvalidToken
from sentry_sdk import capture_exception
from evibes.utils import get_language_from_header
logger = logging.getLogger(__name__)
@ -26,12 +23,6 @@ class CustomCommonMiddleware(CommonMiddleware):
return redirect(f"https://api.{config.BASE_DOMAIN}")
class CustomLocaleCommonMiddleware(CommonMiddleware):
def process_request(self, request):
request.locale = get_language_from_header(request.headers.get("Accept-Language", ""))
translation.activate(request.locale)
class GrapheneJWTAuthorizationMiddleware:
def resolve(self, next, root, info, **args):
context = info.context
@ -54,20 +45,6 @@ class GrapheneJWTAuthorizationMiddleware:
return user
class GrapheneLocaleMiddleware:
def resolve(self, next, root, info, **args):
context = info.context
request = context
accept_language = request.headers.get("Accept-Language", "")
selected_language = get_language_from_header(accept_language)
request.locale = selected_language
translation.activate(request.locale)
return next(root, info, **args)
class BlockInvalidHostMiddleware:
def __init__(self, get_response):
self.get_response = get_response

View file

@ -103,7 +103,6 @@ MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
"evibes.middleware.CustomCommonMiddleware",
"evibes.middleware.CustomLocaleCommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",

View file

@ -4,12 +4,10 @@ GRAPHENE = {
"MIDDLEWARE": [
"evibes.middleware.GrapheneLoggingErrorsDebugMiddleware",
"evibes.middleware.GrapheneJWTAuthorizationMiddleware",
"evibes.middleware.GrapheneLocaleMiddleware",
]
if DEBUG # noqa: F405
else [
"evibes.middleware.GrapheneJWTAuthorizationMiddleware",
"evibes.middleware.GrapheneLocaleMiddleware",
],
"CAMELCASE_ERRORS": True,
}