-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Ziafazal/304: Multi-tenant/multi-site support in Comprehensive Theming #11480
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,22 @@ | ||
| """ | ||
| Core logic for Comprehensive Theming. | ||
| """ | ||
| import os.path | ||
| from path import Path | ||
|
|
||
| from django.conf import settings | ||
| from django.contrib.sites.shortcuts import get_current_site | ||
|
|
||
| from edxmako.middleware import REQUEST_CONTEXT | ||
| from util.url import strip_port_from_host | ||
|
|
||
| def comprehensive_theme_changes(theme_dir): | ||
|
|
||
| def comprehensive_theme_changes(themes_dir): | ||
| """ | ||
| Calculate the set of changes needed to enable a comprehensive theme. | ||
|
|
||
| Arguments: | ||
| theme_dir (path.path): the full path to the theming directory to use. | ||
| themes_dir (path.path): the full path to the directory where all themse are listed. | ||
|
|
||
| Returns: | ||
| A dict indicating the changes to make: | ||
|
|
@@ -27,27 +32,20 @@ def comprehensive_theme_changes(theme_dir): | |
| 'settings': {}, | ||
| 'template_paths': [], | ||
| } | ||
| root = Path(settings.PROJECT_ROOT) | ||
| if root.name == "": | ||
| root = root.parent | ||
|
|
||
| component_dir = theme_dir / root.name | ||
|
|
||
| templates_dir = component_dir / "templates" | ||
| if templates_dir.isdir(): | ||
| changes['template_paths'].append(templates_dir) | ||
| root_name = get_project_root_name() | ||
|
|
||
| staticfiles_dir = component_dir / "static" | ||
| if staticfiles_dir.isdir(): | ||
| changes['settings']['STATICFILES_DIRS'] = [staticfiles_dir] + settings.STATICFILES_DIRS | ||
| if themes_dir.isdir(): | ||
| changes['template_paths'].append(themes_dir) | ||
|
|
||
| locale_dir = component_dir / "conf" / "locale" | ||
| if locale_dir.isdir(): | ||
| changes['settings']['LOCALE_PATHS'] = [locale_dir] + settings.LOCALE_PATHS | ||
| for theme_dir in os.listdir(themes_dir): | ||
| staticfiles_dir = os.path.join(themes_dir, theme_dir, root_name, "static") | ||
| if staticfiles_dir.isdir(): | ||
| changes['settings']['STATICFILES_DIRS'] = settings.STATICFILES_DIRS + [staticfiles_dir] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static file lookups will be handled custom
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each theme is added to |
||
|
|
||
| favicon = component_dir / "static" / "images" / "favicon.ico" | ||
| if favicon.isfile(): | ||
| changes['settings']['FAVICON_PATH'] = str(favicon) | ||
| locale_dir = os.path.join(themes_dir, theme_dir, root_name, "conf", "locale") | ||
| if locale_dir.isdir(): | ||
| changes['settings']['LOCALE_PATHS'] = [locale_dir] + settings.LOCALE_PATHS | ||
|
|
||
| return changes | ||
|
|
||
|
|
@@ -64,3 +62,44 @@ def enable_comprehensive_theme(theme_dir): | |
| for template_dir in changes['template_paths']: | ||
| settings.DEFAULT_TEMPLATE_ENGINE['DIRS'].insert(0, template_dir) | ||
| settings.MAKO_TEMPLATES['main'].insert(0, template_dir) | ||
|
|
||
|
|
||
| def get_template_path(relative_path): | ||
| """ | ||
| Returns a path (string) to a Mako template, if one is found in theme directory | ||
| otherwise return what is passed. | ||
| """ | ||
| request = getattr(REQUEST_CONTEXT, 'request', None) | ||
| if not request: | ||
| return relative_path | ||
|
|
||
| domain = get_current_site(request).domain | ||
| domain = strip_port_from_host(domain) | ||
| root_name = get_project_root_name() | ||
| template_path = "/".join([ | ||
| settings.COMPREHENSIVE_THEME_DIR, | ||
| domain, | ||
| root_name, | ||
| "templates" | ||
| ]) | ||
|
|
||
| search_path = os.path.join(template_path, relative_path) | ||
| if os.path.isfile(search_path): | ||
| path = '/{domain}/{root_name}/templates/{relative_path}'.format( | ||
| domain=domain, | ||
| root_name=root_name, | ||
| relative_path=relative_path, | ||
| ) | ||
| return path | ||
| else: | ||
| return relative_path | ||
|
|
||
|
|
||
| def get_project_root_name(): | ||
| """ | ||
| :return: | ||
| """ | ||
| root = Path(settings.PROJECT_ROOT) | ||
| if root.name == "": | ||
| root = root.parent | ||
| return root.name | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ## mako | ||
| <div> Jane's footer</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These microsite references should be routed through the theming app -- the goal of this work is two-fold: to support multiple sites with comprehensive theming and eliminate the existing microsites implementation.