Skip to content

preferred language #810

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

Merged
merged 3 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions app/app/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.

"""
from app.utils import sync_profile
from app.utils import setup_lang, sync_profile


def save_profile(backend, user, response, *args, **kwargs):
def save_profile(backend, user, response, request, *args, **kwargs):

"""Associate a Profile with a User."""
if backend.name == 'github':
handle = user.username
sync_profile(handle, user)
setup_lang(handle, request)
10 changes: 10 additions & 0 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import rollbar

import environ
from django.utils.translation import gettext_lazy as _


root = environ.Path(__file__) - 2 # Set the base directory to two levels.
env = environ.Env(DEBUG=(bool, False), ) # set default values and casting
Expand Down Expand Up @@ -170,6 +172,14 @@
USE_TZ = env.bool('USE_TZ', default=True)
TIME_ZONE = env.str('TIME_ZONE', default='UTC')

LOCALE_PATHS = (
'locale',
)

LANGUAGES = [
('en', _('English'))
]

if not ENV in ['local', 'test']:
LOGGING = {
'version': 1,
Expand Down
6 changes: 6 additions & 0 deletions app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db.models import Lookup
from django.db.models.fields import Field
from django.utils import timezone
from django.utils.translation import LANGUAGE_SESSION_KEY

import requests
import rollbar
Expand Down Expand Up @@ -71,6 +72,11 @@ def add_contributors(repo_data):
return repo_data


def setup_lang(handle, request):
profile = Profile.objects.get(handle=handle)
request.session[LANGUAGE_SESSION_KEY] = profile.get_profile_preferred_language()


def sync_profile(handle, user=None):
data = get_user(handle)
email = ''
Expand Down
19 changes: 19 additions & 0 deletions app/dashboard/migrations/0061_profile_pref_lang_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.0.3 on 2018-04-24 23:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0060_tool_modifications'),
]

operations = [
migrations.AddField(
model_name='profile',
name='pref_lang_code',
field=models.CharField(choices=[('en', 'English')], default='en', max_length=2),
preserve_default=False,
),
]
4 changes: 3 additions & 1 deletion app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ class Profile(SuperModel):
last_sync_date = models.DateTimeField(null=True)
email = models.CharField(max_length=255, blank=True, db_index=True)
github_access_token = models.CharField(max_length=255, blank=True, db_index=True)
pref_lang_code = models.CharField(max_length=2, choices=settings.LANGUAGES)
suppress_leaderboard = models.BooleanField(
default=False,
help_text='If this option is chosen, we will remove your profile information from the leaderboard',
Expand Down Expand Up @@ -1060,14 +1061,15 @@ def get_access_token(self, save=True):
return ''
return access_token

def get_profile_preferred_language(self):
return settings.LANGUAGE_CODE if self.pref_lang_code is None else self.pref_lang_code

@receiver(user_logged_in)
def post_login(sender, request, user, **kwargs):
"""Handle actions to take on user login."""
from dashboard.utils import create_user_action
create_user_action(user, 'Login', request)


@receiver(user_logged_out)
def post_logout(sender, request, user, **kwargs):
"""Handle actions to take on user logout."""
Expand Down
Loading