-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
preferred language #810
Conversation
I leave Polish locales (translated only navbar) to allow You check how it works locally. I'll remove them before final push. User can change preferred language in email settings, I hope it will be moved to profile settings in #795. |
4473d0b
to
0e39abf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider
app/marketing/views.py
Outdated
@@ -420,6 +421,15 @@ def email_settings(request, key): | |||
else: | |||
raise Http404 | |||
es = es.first() | |||
profile_id = request.session.get('profile_id') | |||
profile = Profile.objects.get(pk=profile_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to check if profile_id is None
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder if it's possible... can user without profile change preferences ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An anonymous user can still hit the https://gitcoin.co/email/settings/
endpoint at the moment. We'll want to either restrict the view from being accessed without auth or handle when profile_id = request.session.get('profile_id')
is None
😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preferred_language selection will be available only if profile_id is present in session data, is it fine ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kziemianek 👍 Works for me! Realistically, we'll restrict this view from being accessed by users that haven't authenticated, so that should work!
app/dashboard/models.py
Outdated
@@ -684,6 +684,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=10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should limit the choices to LANGUAGES
and we can probably set the max_length
to 2.
app/marketing/views.py
Outdated
@@ -420,6 +421,15 @@ def email_settings(request, key): | |||
else: | |||
raise Http404 | |||
es = es.first() | |||
profile_id = request.session.get('profile_id') | |||
profile = Profile.objects.get(pk=profile_id) | |||
if request.POST.get('preferred_language', False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop the False
here. We could probably just do:
preferred_language = request.POST.get('preferred_language')
if preferred_language:
profile.pref_lang_code = preferred_language
profile.save()
Also should we assert preferred_language is in LANGUAGES?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also should we assert preferred_language is in LANGUAGES?
Yes !! Better safe than sorry
app/marketing/views.py
Outdated
@@ -420,6 +421,15 @@ def email_settings(request, key): | |||
else: | |||
raise Http404 | |||
es = es.first() | |||
profile_id = request.session.get('profile_id') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note... This is changing and will soon be: profile = request.user.profile
app/github/views.py
Outdated
session_data = { | ||
'handle': user_profile.handle, | ||
'email': user_profile.email, | ||
'access_token': user_profile.github_access_token, | ||
'profile_id': user_profile.pk, | ||
'name': user_profile.data.get('name', None), | ||
'access_token_last_validated': timezone.now().isoformat(), | ||
} | ||
for k, v in session_data.items(): | ||
LANGUAGE_SESSION_KEY: user_profile.pref_lang_code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user doesn't have pref_lang_code
set, we shouldn't manipulate LANGUAGE_SESSION_KEY
.
<label class="form__label" for="level">{% trans "Preferred language" %}</label> | ||
<div class="form__select"> | ||
<select id="preferred_language" name="preferred_language" required> | ||
{% get_language_info_list for available_languages as langs %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to replace this with:
{% get_available_languages as global_languages %}
{% get_language_info_list for global_languages as langs %}
Then you can eliminate the 'available_languages': ['en', 'pl'],
part all together.
app/marketing/views.py
Outdated
@@ -464,6 +474,8 @@ def email_settings(request, key): | |||
'msg': msg, | |||
'autocomplete_keywords': json.dumps( | |||
[str(key) for key in Keyword.objects.all().values_list('keyword', flat=True)]), | |||
'available_languages': ['en', 'pl'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed per the comment below.
Codecov Report
@@ Coverage Diff @@
## master #810 +/- ##
==========================================
- Coverage 33.08% 32.68% -0.41%
==========================================
Files 100 100
Lines 6435 6539 +104
Branches 780 783 +3
==========================================
+ Hits 2129 2137 +8
- Misses 4208 4304 +96
Partials 98 98
Continue to review full report at Codecov.
|
app/github/views.py
Outdated
session_data = { | ||
'handle': user_profile.handle, | ||
'email': user_profile.email, | ||
'access_token': user_profile.github_access_token, | ||
'profile_id': user_profile.pk, | ||
'name': user_profile.data.get('name', None), | ||
'access_token_last_validated': timezone.now().isoformat(), | ||
LANGUAGE_SESSION_KEY: user_profile.pref_lang_code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove this in favor of the if check below?
@@ -47,7 +47,7 @@ <h5>{% trans "Basic Preferences" %}</h5> | |||
</div> | |||
<div class="form-group"> | |||
<label class="form__label" for="level">{% trans "Send me" %}</label> | |||
<div class="form__select"> | |||
<div class="form__select"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the trailing whitespace here?
app/marketing/views.py
Outdated
@@ -420,6 +421,15 @@ def email_settings(request, key): | |||
else: | |||
raise Http404 | |||
es = es.first() | |||
profile_id = request.session.get('profile_id') | |||
profile = Profile.objects.get(pk=profile_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An anonymous user can still hit the https://gitcoin.co/email/settings/
endpoint at the moment. We'll want to either restrict the view from being accessed without auth or handle when profile_id = request.session.get('profile_id')
is None
😢
4cf40a5
to
8ce6496
Compare
8ce6496
to
bd2adf3
Compare
bd2adf3
to
6315636
Compare
Tests fix in #860 |
6315636
to
863ba2c
Compare
@kziemianek Mind resolving the conflicts here and we'll get it merged? |
534525c
to
41a5706
Compare
app/app/settings.py
Outdated
'locale', | ||
) | ||
|
||
LANGUAGES = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
app/app/settings.py
Outdated
) | ||
|
||
LANGUAGES = [ | ||
('en', _('English')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
app/app/settings.py
Outdated
@@ -405,3 +415,4 @@ | |||
}] | |||
SILKY_MAX_RECORDED_REQUESTS_CHECK_PERCENT = env.int( | |||
'SILKY_MAX_RECORDED_REQUESTS_CHECK_PERCENT', default=10) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W391 blank line at end of file
W293 blank line contains whitespace
app/app/utils.py
Outdated
@@ -55,6 +56,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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
app/app/utils.py
Outdated
@@ -90,7 +96,7 @@ def sync_profile(handle, user=None): | |||
except Exception as e: | |||
logger.error(e) | |||
return None | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W293 blank line contains whitespace
app/marketing/views.py
Outdated
@@ -575,23 +577,34 @@ def email_settings(request, key): | |||
suppress_leaderboard = False | |||
email = '' | |||
level = '' | |||
msg = '' | |||
|
|||
msg = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
app/marketing/views.py
Outdated
if request.POST and request.POST.get('submit'): | ||
email = request.POST.get('email') | ||
level = request.POST.get('level') | ||
profile = Profile.objects.get(pk=request.user.profile.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
app/marketing/views.py
Outdated
if request.POST and request.POST.get('submit'): | ||
email = request.POST.get('email') | ||
level = request.POST.get('level') | ||
profile = Profile.objects.get(pk=request.user.profile.id) | ||
if profile: | ||
pref_lang = profile.get_profile_preferred_language(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E703 statement ends with a semicolon
app/marketing/views.py
Outdated
@@ -603,14 +616,17 @@ def email_settings(request, key): | |||
else: | |||
es.metadata['ip'].append(ip) | |||
es.save() | |||
msg = "Updated your preferences. " | |||
msg = "Updated your preferences. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
app/marketing/views.py
Outdated
context = { | ||
'nav': 'internal', | ||
'active': '/settings/email', | ||
'title': _('Email Settings'), | ||
'es': es, | ||
'msg': msg, | ||
'navs': settings_navs, | ||
'available_languages': ['en', 'pl'], | ||
'preferred_language': pref_lang, | ||
'logged_in' : False if request.session.get('profile_id') is None else True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E203 whitespace before ':'
1701c4b
to
0047d19
Compare
app/dashboard/models.py
Outdated
@@ -827,7 +827,8 @@ class Profile(SuperModel): | |||
handle = models.CharField(max_length=255, db_index=True) | |||
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) | |||
github_access_token = models.CharField(max_length=255, blank=True, db_index=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
cf7b16d
to
6d439a7
Compare
app/dashboard/models.py
Outdated
|
||
@receiver(user_logged_out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E303 too many blank lines (2)
6d439a7
to
4a1c05d
Compare
@@ -0,0 +1,19 @@ | |||
# Generated by Django 2.0.3 on 2018-04-19 17:47 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/dashboard/models.py
Outdated
@@ -1043,19 +1044,20 @@ def get_access_token(self, save=True): | |||
return '' | |||
return access_token | |||
|
|||
@receiver(user_logged_in) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These shouldn't be on Profile
. Can you indent them back?
app/dashboard/models.py
Outdated
"""Handle actions to take on user logout.""" | ||
from dashboard.utils import create_user_action | ||
create_user_action(user, 'Logout', request) | ||
def get_profile_preferred_language(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to move this back up to Profile
after you move the signals out.
app/marketing/mails.py
Outdated
preferred_language = profile.get_profile_preferred_language() | ||
translation.activate(preferred_language) | ||
except Profile.DoesNotExist: | ||
print(f'-- Could not determine recipient preferred email, using default.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for literal string interpolation here since we're not using any vars.
app/marketing/views.py
Outdated
@@ -611,6 +624,8 @@ def email_settings(request, key): | |||
'es': es, | |||
'msg': msg, | |||
'navs': settings_navs, | |||
'available_languages': ['en', 'pl'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop this now that you're doing: {% get_available_languages as LANGUAGES %}
and {% get_language_info_list for LANGUAGES as langs %}
4a1c05d
to
2caf41b
Compare
2caf41b
to
621282c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 🙌
do we need to do more regression testing here? this is just a random feature i tried |
Description
Allow the user to set different language for the Gitcoin app
Checklist
Affected core subsystem(s)
backend, frontend
Testing
locally
Refers/Fixes
Refs: #802