def load(self): domain_method = self.siteconfig.get("site_domain_method") site = Site.objects.get_current() can_enable_search, reason = get_can_enable_search() if not can_enable_search: self.disabled_fields['search_enable'] = True self.disabled_fields['search_index_file'] = True self.disabled_reasons['search_enable'] = reason # Load the rest of the settings from the form. super(GeneralSettingsForm, self).load() # Load the cache settings. cache_backend = normalize_cache_backend( self.siteconfig.get('cache_backend')) cache_type = self.CACHE_TYPES_MAP.get(cache_backend['BACKEND'], 'custom') self.fields['cache_type'].initial = cache_type if settings.DEBUG: self.fields['cache_type'].choices += ( ('locmem', _('Local memory cache')), ) if cache_type == 'custom': self.fields['cache_type'].choices += ( ('custom', _('Custom')), ) cache_locations = [] elif cache_type != 'locmem': cache_locations = cache_backend['LOCATION'] if not isinstance(cache_locations, list): cache_locations = [cache_locations] location_field = self.CACHE_LOCATION_FIELD_MAP[cache_type] self.fields[location_field].initial = ';'.join(cache_locations) # This must come after we've loaded the general settings. self.fields['server'].initial = "%s://%s" % (domain_method, site.domain)
def load(self): domain_method = self.siteconfig.get("site_domain_method") site = Site.objects.get_current() can_enable_search, reason = get_can_enable_search() if not can_enable_search: self.disabled_fields['search_enable'] = True self.disabled_fields['search_index_file'] = True self.disabled_reasons['search_enable'] = reason # Load the rest of the settings from the form. super(GeneralSettingsForm, self).load() # Load the cache settings. cache_backend = normalize_cache_backend( self.siteconfig.get('cache_backend')) cache_type = self.CACHE_TYPES_MAP.get(cache_backend['BACKEND'], 'custom') self.fields['cache_type'].initial = cache_type if settings.DEBUG: self.fields['cache_type'].choices += (('locmem', _('Local memory cache')), ) if cache_type == 'custom': self.fields['cache_type'].choices += (('custom', _('Custom')), ) cache_locations = [] elif cache_type != 'locmem': cache_locations = cache_backend['LOCATION'] if not isinstance(cache_locations, list): cache_locations = [cache_locations] location_field = self.CACHE_LOCATION_FIELD_MAP[cache_type] self.fields[location_field].initial = ';'.join(cache_locations) # This must come after we've loaded the general settings. self.fields['server'].initial = "%s://%s" % (domain_method, site.domain)
def _set_cache_backend(settings, key, value): settings.CACHES[DEFAULT_CACHE_ALIAS] = normalize_cache_backend(value)