def in_preview_mode(): """ Returns whether the user is in preview mode or not. """ hostname = get_current_request_hostname() preview_lms_base = settings.FEATURES.get('PREVIEW_LMS_BASE', None) return bool(preview_lms_base and hostname and hostname.split(':')[0] == preview_lms_base.split(':')[0])
def in_preview_mode(): """ Returns whether the user is in preview mode or not. """ hostname = get_current_request_hostname() preview_lms_base = settings.FEATURES.get('PREVIEW_LMS_BASE', None) return bool(preview_lms_base and hostname and hostname.split(':')[0] == preview_lms_base.split(':')[0])
def get_branch_setting(): """ Finds and returns the branch setting based on the Django request and the configuration settings """ branch = None hostname = get_current_request_hostname() if hostname: # [COLARAZ-CUSTOM] # By default, edX saves preview domain mappings in HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS (in production.py) # using PREVIEW_LMS_BASE. But doing this, the preview functionality works only for single site. # To make this functional for multisites, if our domain contains the preview key, we are returning the # mapping by ourselves. if settings.COLARAZ_PREVIEW_DOMAIN_KEY in hostname: return 'draft-preferred' # get mapping information which is defined in configurations mappings = getattr(settings, 'HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS', None) # compare hostname against the regex expressions set of mappings which will tell us which branch to use if mappings: for key in mappings.iterkeys(): if re.match(key, hostname): return mappings[key] if branch is None: branch = getattr(settings, 'MODULESTORE_BRANCH', None) return branch
def marketing_link(name): """Returns the correct URL for a link to the marketing site depending on if the marketing site is enabled Since the marketing site is enabled by a setting, we have two possible URLs for certain links. This function is to decides which URL should be provided. """ # link_map maps URLs from the marketing site to the old equivalent on # the Django site link_map = settings.MKTG_URL_LINK_MAP enable_mktg_site = configuration_helpers.get_value( 'ENABLE_MKTG_SITE', settings.FEATURES.get('ENABLE_MKTG_SITE', False)) marketing_urls = configuration_helpers.get_value('MKTG_URLS', settings.MKTG_URLS) marketing_url_overrides = configuration_helpers.get_value( 'MKTG_URL_OVERRIDES', settings.MKTG_URL_OVERRIDES) if name in marketing_url_overrides: validate = URLValidator() url = marketing_url_overrides.get(name) try: validate(url) return url except ValidationError as err: log.debug("Invalid link set for link %s: %s", name, err) return '#' if enable_mktg_site and name in marketing_urls: # special case for when we only want the root marketing URL if name == 'ROOT': return marketing_urls.get('ROOT') # special case for new enterprise marketing url with custom tracking query params if name == 'ENTERPRISE': enterprise_url = marketing_urls.get(name) # if url is not relative, then return it without joining to root if not enterprise_url.startswith('/'): return enterprise_url # Using urljoin here allows us to enable a marketing site and set # a site ROOT, but still specify absolute URLs for other marketing # URLs in the MKTG_URLS setting # e.g. urljoin('http://marketing.com', 'http://open-edx.org/about') >>> 'http://open-edx.org/about' return urljoin(marketing_urls.get('ROOT'), marketing_urls.get(name)) # only link to the old pages when the marketing site isn't on elif not enable_mktg_site and name in link_map: # don't try to reverse disabled marketing links if link_map[name] is not None: host_name = get_current_request_hostname() if all( [host_name and 'edge' in host_name, 'http' in link_map[name]]): return link_map[name] else: return reverse(link_map[name]) else: log.debug(u"Cannot find corresponding link for name: %s", name) return '#'
def get_branch_setting(): """ Finds and returns the branch setting based on the Django request and the configuration settings """ branch = None hostname = get_current_request_hostname() if hostname: # get mapping information which is defined in configurations mappings = getattr(settings, 'HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS', None) # compare hostname against the regex expressions set of mappings which will tell us which branch to use if mappings: for key in mappings.iterkeys(): if re.match(key, hostname): return mappings[key] if branch is None: branch = getattr(settings, 'MODULESTORE_BRANCH', None) return branch
def get_branch_setting(): """ Finds and returns the branch setting based on the Django request and the configuration settings """ branch = None hostname = get_current_request_hostname() if hostname: # [REDHOUSE CUSTOM] # Here we are checking if the request is from Preview site simply allow the draft view if get_configuration_value('PREVIEW_LMS_BASE', '') == hostname: return 'draft-preferred' # get mapping information which is defined in configurations mappings = getattr(settings, 'HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS', None) # compare hostname against the regex expressions set of mappings which will tell us which branch to use if mappings: for key in mappings.iterkeys(): if re.match(key, hostname): return mappings[key] if branch is None: branch = getattr(settings, 'MODULESTORE_BRANCH', None) return branch
def test_get_current_request_hostname(self): """ Since we are running outside of Django assert that get_current_request_hostname returns None """ assert get_current_request_hostname() is None
def test_get_current_request_hostname(self): """ Since we are running outside of Django assert that get_current_request_hostname returns None """ assert get_current_request_hostname() is None