def url(self, name): """ Returns url of the asset, themed url will be returned if the asset is themed otherwise default asset url will be returned. Args: name: name of the asset, e.g. 'images/logo.png' Returns: url of the asset, e.g. '/static/red-theme/images/logo.png' if current theme is red-theme and logo is provided by red-theme otherwise '/static/images/logo.png' """ prefix = '' theme = get_current_theme() # get theme prefix from site address if if asset is accessed via a url if theme: prefix = theme.theme_dir_name # get theme prefix from storage class, if asset is accessed during collectstatic run elif self.prefix: prefix = self.prefix # join theme prefix with asset name if theme is applied and themed asset exists if prefix and self.themed(name, prefix): name = os.path.join(prefix, name) return super(ThemeStorage, self).url(name)
def url(self, name): """ Returns url of the asset, themed url will be returned if the asset is themed otherwise default asset url will be returned. Args: name: name of the asset, e.g. 'images/logo.png' Returns: url of the asset, e.g. '/static/red-theme/images/logo.png' if current theme is red-theme and logo is provided by red-theme otherwise '/static/images/logo.png' """ prefix = '' theme = get_current_theme() # get theme prefix from site address if if asset is accessed via a url if theme: prefix = theme.theme_dir_name # get theme prefix from storage class, if asset is accessed during collectstatic run elif self.prefix: prefix = self.prefix # join theme prefix with asset name if theme is applied and themed asset exists if prefix and self.themed(name, prefix): name = os.path.join(prefix, name) return super(ThemeStorage, self).url(name)
def get_theme_template_sources(): """ Return template sources for the given theme and if request object is None (this would be the case for management commands) return template sources for all themes. """ if not get_current_request(): # if request object is not present, then this method is being called inside a management # command and return all theme template sources for compression return get_all_theme_template_dirs() else: # template is being accessed by a view, so return templates sources for current theme theme = get_current_theme() return theme and theme.template_dirs
def get_theme_template_sources(): """ Return template sources for the given theme and if request object is None (this would be the case for management commands) return template sources for all themes. """ if not get_current_request(): # if request object is not present, then this method is being called inside a management # command and return all theme template sources for compression return get_all_theme_template_dirs() else: # template is being accessed by a view, so return templates sources for current theme theme = get_current_theme() return theme and theme.template_dirs
def url(self, name, force=False): """ Returns themed url for the given asset. """ theme = get_current_theme() if theme and theme.theme_dir_name not in name: # during server run, append theme name to the asset name if it is not already there # this is ensure that correct hash is created and default asset is not always # used to create hash of themed assets. name = os.path.join(theme.theme_dir_name, name) parsed_name = urlsplit(unquote(name)) clean_name = parsed_name.path.strip() asset_name = name if not self.exists(clean_name): # if themed asset does not exists then use default asset theme = name.split("/", 1)[0] # verify that themed asset was accessed if theme in [theme.theme_dir_name for theme in get_themes()]: asset_name = "/".join(name.split("/")[1:]) return super(ThemeCachedFilesMixin, self).url(asset_name, force)
def render_include(context, path): __M_caller = context.caller_stack._push_frame() try: list = context.get('list', UNDEFINED) __M_writer = context.writer() from django.conf import settings from django.template.engine import Engine from django.template.loaders.filesystem import Loader from openedx.core.djangoapps.theming.helpers import get_current_theme dirs = settings.DEFAULT_TEMPLATE_ENGINE['DIRS'] theme = get_current_theme() if theme: dirs = list(dirs) dirs.insert(0, theme.path / 'templates') engine = Engine(dirs=dirs) source, template_path = Loader(engine).load_template_source(path) __M_writer(filters.decode.utf8(source)) return '' finally: context.caller_stack._pop_frame()
def _processed_asset_name(self, name): """ Returns either a themed or unthemed version of the given asset name, depending on several factors. See the class docstring for more info. """ theme = get_current_theme() if theme and theme.theme_dir_name not in name: # during server run, append theme name to the asset name if it is not already there # this is ensure that correct hash is created and default asset is not always # used to create hash of themed assets. name = os.path.join(theme.theme_dir_name, name) parsed_name = urlsplit(unquote(name)) clean_name = parsed_name.path.strip() asset_name = name if not self.exists(clean_name): # if themed asset does not exists then use default asset theme = name.split("/", 1)[0] # verify that themed asset was accessed if theme in [theme.theme_dir_name for theme in get_themes()]: asset_name = "/".join(name.split("/")[1:]) return asset_name
def _processed_asset_name(self, name): """ Returns either a themed or unthemed version of the given asset name, depending on several factors. See the class docstring for more info. """ theme = get_current_theme() if theme and theme.theme_dir_name not in name: # during server run, append theme name to the asset name if it is not already there # this is ensure that correct hash is created and default asset is not always # used to create hash of themed assets. name = os.path.join(theme.theme_dir_name, name) parsed_name = urlsplit(unquote(name)) clean_name = parsed_name.path.strip() asset_name = name if not self.exists(clean_name): # if themed asset does not exists then use default asset theme = name.split("/", 1)[0] # verify that themed asset was accessed if theme in [theme.theme_dir_name for theme in get_themes()]: asset_name = "/".join(name.split("/")[1:]) return asset_name