From 3890a38ca1d4667bdfc06b4e23345b828b26e815 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Thu, 26 May 2022 10:10:23 +0530 Subject: [PATCH] fix: truncate site name if longer than 50 characters and show warning Close #518 --- CHANGELOG.md | 1 + tutor/jobs.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37b624b..d300630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Every user-facing change should have an entry in this changelog. Please respect ## Unreleased +- [Fix] Truncate site display name to 50 characters with a warning, fixing data too long error for long site names. (by @navinkarkera) - [Feature] Add patch to allow overriding final openedx docker image CMD - [Fix] Ignore Python plugins that cannot be loaded. (by @regisb) - [Improvement] Faster and more reliable builds with `npm clean-install` instead of `npm install`. (by @regisb. Thanks @ghassanmas!) diff --git a/tutor/jobs.py b/tutor/jobs.py index cd80d3b..e90aaa2 100644 --- a/tutor/jobs.py +++ b/tutor/jobs.py @@ -126,11 +126,18 @@ def set_theme( return python_code = "from django.contrib.sites.models import Site" for domain_name in domain_names: + if len(domain_name) > 50: + fmt.echo_alert( + "Assigning a theme to a site with a long (> 50 characters) domain name." + " The displayed site name will be truncated to 50 characters." + ) python_code += """ print('Assigning theme {theme_name} to {domain_name}...') site, _ = Site.objects.get_or_create(domain='{domain_name}') if not site.name: - site.name = '{domain_name}' + name_max_length = Site._meta.get_field('name').max_length + name = '{domain_name}'[:name_max_length] + site.name = name site.save() site.themes.all().delete() site.themes.create(theme_dir_name='{theme_name}')