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

settheme command just creates site objects #1098

Open
CodeWithEmad opened this issue Jul 22, 2024 · 0 comments
Open

settheme command just creates site objects #1098

CodeWithEmad opened this issue Jul 22, 2024 · 0 comments

Comments

@CodeWithEmad
Copy link
Member

A job will run the following script when we run the settheme command.

def set_theme_template(theme_name: str, domain_names: list[str]) -> str:
"""
For each domain, get or create a Site object and assign the selected theme.
"""
# Note that there are no double quotes " in this piece of code
python_command = """
import sys
from django.contrib.sites.models import Site
def assign_theme(name, domain):
print('Assigning theme', name, 'to', domain)
if len(domain) > 50:
sys.stderr.write(
'Assigning a theme to a site with a long (> 50 characters) domain name.'
' The displayed site name will be truncated to 50 characters.\\n'
)
site, _ = Site.objects.get_or_create(domain=domain)
if not site.name:
name_max_length = Site._meta.get_field('name').max_length
site.name = domain[:name_max_length]
site.save()
site.themes.all().delete()
if name != 'default':
site.themes.create(theme_dir_name=name)
"""
domain_names = domain_names or [
"{{ LMS_HOST }}",
"{{ LMS_HOST }}:8000",
"{{ CMS_HOST }}",
"{{ CMS_HOST }}:8001",
"{{ PREVIEW_LMS_HOST }}",
"{{ PREVIEW_LMS_HOST }}:8000",
]
for domain_name in domain_names:
python_command += f"assign_theme('{theme_name}', '{domain_name}')\n"
return f'./manage.py lms shell -c "{python_command}"'

This is fine when we're going to Create an organization, and in the process, many configurations will be saved in the SiteConfiguration objects, using those sites. If you change your LMS_HOST, CMS_HOST, etc, and run the settheme command, only new site objects will be created, but no new config created (or old configs` sites updated to use the new site objects).

When creating an organization, various configurations are saved in the SiteConfiguration objects (like "ENABLE_PROFILE_MICROFRONTEND": "true") and applied to the sites. If you modify LMS_HOST, CMS_HOST, etc., and execute the settheme command, new site objects will be created. However, no new configurations will be created, and the old configurations' sites will not be updated to use the new site objects.

@DawoudSheraz DawoudSheraz moved this from Pending Triage to Backlog in Tutor project management Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant