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: # 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_default_store_name_for_current_request(): """ This method will return the appropriate default store mapping for the current Django request, else 'default' which is the system default """ store_name = 'default' # see what request we are currently processing - if any at all - and get hostname for the request hostname = get_current_request_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 store name to use if hostname and mappings: for key in mappings.keys(): if re.match(key, hostname): store_name = mappings[key] return store_name return store_name
def test_get_current_request_hostname(self): """ Since we are running outside of Django assert that get_current_request_hostname returns None """ assert_is_none(get_current_request_hostname())
def in_preview_mode(): """ Returns whether the user is in preview mode or not. """ hostname = get_current_request_hostname() return bool(hostname and settings.PREVIEW_DOMAIN in hostname.split('.'))
def in_preview_mode(): """ Returns whether the user is in preview mode or not. """ hostname = get_current_request_hostname() return hostname and settings.PREVIEW_DOMAIN in hostname.split('.')