Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update UserChangeLanguage middleware #567

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions bothub/api/v2/middleware.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.utils import translation
from django.utils.deprecation import MiddlewareMixin


class UserLanguageMiddleware(MiddlewareMixin):
def process_response(self, request, response):
class UserLanguageMiddleware:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
user = getattr(request, "user", None)
if not user or user.is_anonymous:
return self.get_response(request)
Expand All @@ -15,4 +17,5 @@ def process_response(self, request, response):
translation.activate(user_language)

response = self.get_response(request)

return response