-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
save language preference for user (#1080)
* save language preference for user * respect language for notification * fix loading logentries for models that dont exist --------- Co-authored-by: Felix Rindt <[email protected]>
- Loading branch information
1 parent
57ba281
commit 8964bc9
Showing
10 changed files
with
116 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
ephios/core/migrations/0021_userprofile_preferred_language_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 4.2.4 on 2023-09-30 13:03 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0020_qualificationcategory_show_with_user_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="userprofile", | ||
name="preferred_language", | ||
field=models.CharField( | ||
choices=[("de", "German"), ("en", "English")], | ||
default="de", | ||
max_length=10, | ||
verbose_name="preferred language", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="qualificationcategory", | ||
name="show_with_user", | ||
field=models.BooleanField( | ||
default=True, | ||
verbose_name="Show qualifications of this category everywhere a user is presented", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from contextlib import contextmanager | ||
|
||
from django.conf import settings | ||
from django.utils import translation | ||
|
||
|
||
@contextmanager | ||
def language(lang): | ||
previous_language = translation.get_language() | ||
lang = lang or settings.LANGUAGE_CODE | ||
translation.activate(lang) | ||
try: | ||
yield | ||
finally: | ||
translation.activate(previous_language) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.conf import settings | ||
|
||
|
||
class EphiosLocaleMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
response = self.get_response(request) | ||
if settings.LANGUAGE_COOKIE_NAME not in request.COOKIES: | ||
try: | ||
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, request.user.preferred_language) | ||
except (KeyError, AttributeError): | ||
pass | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters