Skip to content

Commit

Permalink
[BUG FIX] Adds accidentally removed keyword language select on signup (
Browse files Browse the repository at this point in the history
…hedyorg#2064)

* Fix dynamic changing of keyword selector on signup
  • Loading branch information
TiBiBa authored Feb 22, 2022
1 parent 77a04a8 commit 845fe9d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion coursedata/texts/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Auth:
email_invalid: "Please enter a valid email."
year_invalid: "Please enter a year between 1900 and "
language_invalid: "Please select a valid language"
keyword_language_invalid: "Please select a valid keyword language"
keyword_language_invalid: "Please select a valid keyword language (select English or your own language)"
gender_invalid: "Please select a valid gender, choose (Female, Male, Other)"
experience_invalid: "Please select a valid experience, choose (Yes, No)"
programming_invalid: "Please select a valid programming language"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Auth:
email_invalid: "Vul een geldig email in."
year_invalid: "Dit is geen geldig jaartal, die moet liggen tussen 1900 en "
language_invalid: "Dit is geen geldige taal"
keyword_language_invalid: "Dit is geen geldige commando taal"
keyword_language_invalid: "Dit is geen geldige commando taal (kies Engels of je eigen taal)"
gender_invalid: "Dit gender is niet geldig, kies uit (Meisje, Jongen, Anders)"
experience_invalid: "Dit is geen geldige programmeerervaring, kies uit (Ja, Nee)"
programming_invalid: "Dit is geen geldige programmeertaal, kies een ander"
Expand Down
2 changes: 1 addition & 1 deletion static/css/generated.css

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions static/js/appbundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions static/js/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ if (window.location.pathname === '/signup') {
}
}

$("#language").change(function () {
const lang = $(this).val();
$('#keyword_language').val("en");
if (lang == "en" || !($('#' + lang + '_option').length)) {
$('#keyword_lang_container').hide();
} else {
$('.keyword_lang_option').hide();
$('#en_option').show();
$('#' + lang + '_option').show();
$('#keyword_lang_container').show();
}
});

$ ('#email, #mail_repeat').on ('cut copy paste', function (e) {
e.preventDefault ();
return false;
Expand Down
7 changes: 7 additions & 0 deletions templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ <h4 class="text-blue-500 mb-4 text-center">{{auth.create_account_explanation}}</
{% endfor %}
</select>
</div>
<div class="flex flex-row items-center mx-auto w-full my-1 border-b pb-2 border-gray-400" style="display: none;" id="keyword_lang_container">
<label class="inline-block w-1/2" for="keyword_language">{{auth.preferred_keyword_language}}</label><select class="block appearance-none w-1/2 text-gray-700 px-4 py-1 rounded-lg" id="keyword_language" name="keyword_language" required>
{% for language in keyword_languages() %}
<option value="{{language.lang}}" id="{{language.lang}}_option" class="keyword_lang_option" {% if language.lang == "en" %}selected{% endif %}>{{language.sym}}</option>
{% endfor %}
</select>
</div>
<div class="flex flex-row items-center mx-auto w-full my-1 border-b pb-2 border-gray-400">
<label class="inline-block w-1/2" for="birth_year">{{auth.birth_year}}</label><input class="block appearance-none w-1/2 px-2 py-1 rounded-lg border border-gray-400" id="birth_year" min="1900" max="2022" name="birth_year" placeholder="1995" type="number">
</div>
Expand Down
4 changes: 2 additions & 2 deletions website/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def signup():
return g.auth_texts.get('language_invalid'), 400
if not isinstance(body.get('agree_terms'), bool) or not body.get('agree_terms'):
return g.auth_texts.get('agree_invalid'), 400
if not isinstance(body.get('keyword_language'), str):
if not isinstance(body.get('keyword_language'), str) or body.get('keyword_language') not in ['en', body.get('language')]:
return g.auth_texts.get('keyword_language_invalid'), 400

# Validations, optional fields
Expand Down Expand Up @@ -450,7 +450,7 @@ def update_profile(user):
return g.auth_texts.get('email_invalid'), 400
if not isinstance(body.get('language'), str):
return g.auth_texts.get('language_invalid'), 400
if not isinstance(body.get('keyword_language'), str):
if not isinstance(body.get('keyword_language'), str) or body.get('keyword_language') not in ['en', body.get('language')]:
return g.auth_texts.get('keyword_language_invalid'), 400

# Todo TB -> Store all validations inside a function, the signup / profile code is duplicate!
Expand Down
3 changes: 2 additions & 1 deletion website/teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,9 @@ def store_accounts(user):

# Now -> actually store the users in the db
for account in body.get('accounts', []):
# Set the current teacher language as new account language
# Set the current teacher language and keyword language as new account language
account['language'] = g.lang
account['keyword_language'] = g.keyword_lang
store_new_account(account, account.get('email').strip().lower())
if account.get('class'):
class_id = [i.get('id') for i in classes if i.get('name') == account.get('class')][0]
Expand Down

0 comments on commit 845fe9d

Please sign in to comment.