Coverage for src/ptf/middleware.py: 0%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-05 09:56 +0000

1""" 

2See : 

3 - https://docs.djangoproject.com/en/2.2/topics/http/middleware/ 

4 - https://gist.github.com/vstoykov/1366794 

5""" 

6 

7 

8class ForceDefaultLanguageMiddleware: 

9 """ 

10 Ignore Accept-Language HTTP headers 

11 

12 This will force the I18N machinery to always choose settings.LANGUAGE_CODE 

13 as the default initial language, unless another one is set via sessions or cookies 

14 

15 Should be installed *before* any middleware that checks request.META['HTTP_ACCEPT_LANGUAGE'], 

16 namely django.middleware.locale.LocaleMiddleware 

17 """ 

18 

19 def __init__(self, get_response): 

20 self.get_response = get_response 

21 

22 def __call__(self, request): 

23 if "accept-language" in request.headers: 

24 del request.META["HTTP_ACCEPT_LANGUAGE"] 

25 

26 response = self.get_response(request) 

27 return response