Skip to content
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

[frontend] Fixing indentation problems + indentation preferences #995

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
11 changes: 11 additions & 0 deletions inginious/frontend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ def get_app(config):
available_languages = {"en": "English"}
available_languages.update(available_translations)

# available indentation types
available_indentation_types = {
"2": {"text": "2 spaces", "indentUnit": 2, "tabSize": 2, "indentWithTabs": False},
AlexandreDoneux marked this conversation as resolved.
Show resolved Hide resolved
"3": {"text": "3 spaces", "indentUnit": 3, "tabSize": 3, "indentWithTabs": False},
"4": {"text": "4 spaces", "indentUnit": 4, "tabSize": 4, "indentWithTabs": False},
"tabs": {"text": "tabs", "indentUnit": 4, "tabSize": 4, "indentWithTabs": True},
AlexandreDoneux marked this conversation as resolved.
Show resolved Hide resolved
}

l10n_manager = L10nManager()

l10n_manager.translations["en"] = gettext.NullTranslations() # English does not need translation ;-)
Expand All @@ -189,6 +197,7 @@ def get_app(config):
template_helper.add_to_template_globals("get_homepath", get_homepath)
template_helper.add_to_template_globals("pkg_version", __version__)
template_helper.add_to_template_globals("available_languages", available_languages)
template_helper.add_to_template_globals("available_indentation_types", available_indentation_types)
AlexandreDoneux marked this conversation as resolved.
Show resolved Hide resolved
template_helper.add_to_template_globals("_", _)
flask_app.template_helper = template_helper
init_flask_maintenance_mapping(flask_app)
Expand Down Expand Up @@ -242,6 +251,7 @@ def get_app(config):
template_helper.add_to_template_globals("_", _)
template_helper.add_to_template_globals("str", str)
template_helper.add_to_template_globals("available_languages", available_languages)
template_helper.add_to_template_globals("available_indentation_types", available_indentation_types)
template_helper.add_to_template_globals("get_homepath", get_homepath)
template_helper.add_to_template_globals("pkg_version", __version__)
template_helper.add_to_template_globals("allow_registration", config.get("allow_registration", True))
Expand Down Expand Up @@ -302,6 +312,7 @@ def flask_internalerror(e):
flask_app.allow_registration = config.get("allow_registration", True)
flask_app.allow_deletion = config.get("allow_deletion", True)
flask_app.available_languages = available_languages
flask_app.available_indentation_types = available_indentation_types
flask_app.welcome_page = config.get("welcome_page", None)
flask_app.terms_page = config.get("terms_page", None)
flask_app.privacy_page = config.get("privacy_page", None)
Expand Down
3 changes: 1 addition & 2 deletions inginious/frontend/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,7 @@ def configure_authentication(self, database):
"realname": realname,
"email": email,
"password": UserManager.hash_password(password),
"bindings": {},
"language": "en"})
"bindings": {}})
AlexandreDoneux marked this conversation as resolved.
Show resolved Hide resolved

options["superadmins"].append(username)

Expand Down
3 changes: 1 addition & 2 deletions inginious/frontend/pages/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def GET(self):

user_profile = self.database.users.find_one({"ltibindings." + data["task"][0] + "." + data["consumer_key"]: data["username"]})
if user_profile:
self.user_manager.connect_user(user_profile["username"], user_profile["realname"], user_profile["email"],
user_profile["language"], user_profile.get("tos_accepted", False))
self.user_manager.connect_user(user_profile)

if self.user_manager.session_logged_in():
return redirect(self.app.get_homepath() + "/lti/task")
Expand Down
18 changes: 15 additions & 3 deletions inginious/frontend/pages/preferences/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def save_profile(self, userdata, data):
msg = _("Incorrect email.")
return result, msg, error
else:
self.user_manager.connect_user(result["username"], result["realname"], result["email"],
result["language"], result.get("tos_accepted", False))
self.user_manager.set_session_username(data["username"])

# Check if updating the password.
if self.app.allow_registration and len(data["passwd"]) in range(1, 6):
Expand Down Expand Up @@ -73,7 +72,7 @@ def save_profile(self, userdata, data):
return_document=ReturnDocument.AFTER)

# Check if updating language
if data["language"] != userdata["language"]:
if data["language"] != userdata.get("language", "en"):
language = data["language"] if data["language"] in self.app.available_languages else "en"
result = self.database.users.find_one_and_update({"username": self.user_manager.session_username()},
{"$set": {"language": language}},
Expand All @@ -85,6 +84,19 @@ def save_profile(self, userdata, data):
else:
self.user_manager.set_session_language(language)

# check if updating code indentation
if data["code_indentation"] != userdata.get("code_indentation", "4"):
code_indentation = data["code_indentation"] if data["code_indentation"] in self.app.available_indentation_types.keys() else "4"
result = self.database.users.find_one_and_update({"username": self.user_manager.session_username()},
AlexandreDoneux marked this conversation as resolved.
Show resolved Hide resolved
{"$set": {"code_indentation": code_indentation}},
return_document=ReturnDocument.AFTER)
if not result:
error = True
msg = _("Incorrect username.")
return result, msg, error
else:
self.user_manager.set_session_code_indentation(code_indentation)

# Checks if updating name
if len(data["realname"]) > 0:
result = self.database.users.find_one_and_update({"username": self.user_manager.session_username()},
Expand Down
1 change: 0 additions & 1 deletion inginious/frontend/pages/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def register_user(self, data):
"password": passwd_hash,
"activate": activate_hash,
"bindings": {},
"language": self.user_manager._session.get("language", "en"),
AlexandreDoneux marked this conversation as resolved.
Show resolved Hide resolved
"tos_accepted": True
})
try:
Expand Down
Loading
Loading