mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-12 14:17:46 +00:00
💥 improvement: better defaults for the settheme
commands
Previously, the list of domain names to which a theme was assigned had to be specified manually. Now, the themes are automatically assigned to the LMS and the CMS, both in development and production modes.
This commit is contained in:
parent
5a4e3792f4
commit
df6a1c3b4e
@ -4,6 +4,8 @@ Note: Breaking changes between versions are indicated by "💥".
|
||||
|
||||
## Unreleased
|
||||
|
||||
- 💥[Improvement] Change the `settheme` command such that, by default, a custom theme is assigned to the LMS and the CMS, both in production and development mode.
|
||||
|
||||
## v12.1.4 (2021-10-11)
|
||||
|
||||
- [Feature] Add configuration setting `PREVIEW_LMS_BASE` for custom preview domain.
|
||||
|
@ -127,9 +127,7 @@ Setting a new theme
|
||||
|
||||
The default Open edX theme is rather bland, so Tutor makes it easy to switch to a different theme::
|
||||
|
||||
tutor local settheme mytheme $(tutor config printvalue LMS_HOST) $(tutor config printvalue CMS_HOST)
|
||||
|
||||
Notice that we pass the hostnames of the LMS and the CMS to the ``settheme`` command: this is because in Open edX, themes are assigned per domain name.
|
||||
tutor local settheme mytheme
|
||||
|
||||
Out of the box, only the default "open-edx" theme is available. We also developed `Indigo, a beautiful, customizable theme <https://github.com/overhangio/indigo>`__ which is easy to install with Tutor.
|
||||
|
||||
|
@ -152,16 +152,25 @@ def createuser(
|
||||
|
||||
|
||||
@click.command(
|
||||
help="Set a theme for a given domain name. To reset to the default theme , use 'default' as the theme name."
|
||||
help="Assign a theme to the LMS and the CMS. To reset to the default theme , use 'default' as the theme name."
|
||||
)
|
||||
@click.option(
|
||||
"-d",
|
||||
"--domain",
|
||||
"domains",
|
||||
multiple=True,
|
||||
help=(
|
||||
"Limit the theme to these domain names. By default, the theme is "
|
||||
"applied to the LMS and the CMS, both in development and production mode"
|
||||
),
|
||||
)
|
||||
@click.argument("theme_name")
|
||||
@click.argument("domain_names", metavar="domain_name", nargs=-1)
|
||||
@click.pass_obj
|
||||
def settheme(context: Context, theme_name: str, domain_names: List[str]) -> None:
|
||||
def settheme(context: Context, domains: List[str], theme_name: str) -> None:
|
||||
config = tutor_config.load(context.root)
|
||||
runner = ComposeJobRunner(context.root, config, context.docker_compose)
|
||||
for domain_name in domain_names:
|
||||
jobs.set_theme(theme_name, domain_name, runner)
|
||||
domains = domains or jobs.get_all_openedx_domains(config)
|
||||
jobs.set_theme(theme_name, domains, runner)
|
||||
|
||||
|
||||
@click.command(help="Import the demo course")
|
||||
|
@ -322,16 +322,25 @@ def importdemocourse(context: Context) -> None:
|
||||
|
||||
|
||||
@click.command(
|
||||
help="Set a theme for a given domain name. To reset to the default theme , use 'default' as the theme name."
|
||||
help="Assign a theme to the LMS and the CMS. To reset to the default theme , use 'default' as the theme name."
|
||||
)
|
||||
@click.option(
|
||||
"-d",
|
||||
"--domain",
|
||||
"domains",
|
||||
multiple=True,
|
||||
help=(
|
||||
"Limit the theme to these domain names. By default, the theme is "
|
||||
"applied to the LMS and the CMS, both in development and production mode"
|
||||
),
|
||||
)
|
||||
@click.argument("theme_name")
|
||||
@click.argument("domain_names", metavar="domain_name", nargs=-1)
|
||||
@click.pass_obj
|
||||
def settheme(context: Context, theme_name: str, domain_names: List[str]) -> None:
|
||||
def settheme(context: Context, domains: List[str], theme_name: str) -> None:
|
||||
config = tutor_config.load(context.root)
|
||||
runner = K8sJobRunner(context.root, config)
|
||||
for domain_name in domain_names:
|
||||
jobs.set_theme(theme_name, domain_name, runner)
|
||||
domains = domains or jobs.get_all_openedx_domains(config)
|
||||
jobs.set_theme(theme_name, domains, runner)
|
||||
|
||||
|
||||
@click.command(name="exec", help="Execute a command in a pod of the given application")
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import Dict, Iterator, List, Optional, Tuple, Union
|
||||
|
||||
from . import env, fmt, plugins
|
||||
from .types import Config
|
||||
from .types import Config, get_typed
|
||||
|
||||
BASE_OPENEDX_COMMAND = """
|
||||
export DJANGO_SETTINGS_MODULE=$SERVICE_VARIANT.envs.$SETTINGS
|
||||
@ -102,18 +102,35 @@ def import_demo_course(runner: BaseJobRunner) -> None:
|
||||
runner.run_job_from_template("cms", "hooks", "cms", "importdemocourse")
|
||||
|
||||
|
||||
def set_theme(theme_name: str, domain_name: str, runner: BaseJobRunner) -> None:
|
||||
command = BASE_OPENEDX_COMMAND
|
||||
command += """
|
||||
echo "Assigning theme {theme_name} to {domain_name}..."
|
||||
./manage.py lms shell -c "
|
||||
from django.contrib.sites.models import Site
|
||||
def set_theme(theme_name: str, domain_names: List[str], runner: BaseJobRunner) -> None:
|
||||
"""
|
||||
For each domain, get or create a Site object and assign the selected theme.
|
||||
"""
|
||||
if not domain_names:
|
||||
return
|
||||
python_code = "from django.contrib.sites.models import Site"
|
||||
for domain_name in domain_names:
|
||||
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}'
|
||||
site.save()
|
||||
site.themes.all().delete()
|
||||
site.themes.create(theme_dir_name='{theme_name}')"
|
||||
"""
|
||||
command = command.format(theme_name=theme_name, domain_name=domain_name)
|
||||
site.themes.create(theme_dir_name='{theme_name}')
|
||||
""".format(
|
||||
theme_name=theme_name, domain_name=domain_name
|
||||
)
|
||||
command = BASE_OPENEDX_COMMAND + './manage.py lms shell -c "{python_code}"'.format(
|
||||
python_code=python_code
|
||||
)
|
||||
runner.run_job("lms", command)
|
||||
|
||||
|
||||
def get_all_openedx_domains(config: Config) -> List[str]:
|
||||
return [
|
||||
get_typed(config, "LMS_HOST", str),
|
||||
get_typed(config, "LMS_HOST", str) + ":8000",
|
||||
get_typed(config, "CMS_HOST", str),
|
||||
get_typed(config, "CMS_HOST", str) + ":8001",
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user