def load(self): """Load settings from the form. This will populate initial fields based on the site configuration. It takes care to transition legacy (<= Review Board 1.7) cache backends, if still used in production, to a modern configuration. """ domain_method = self.siteconfig.get('site_domain_method') site = Site.objects.get_current() # Load the rest of the settings from the form. super(GeneralSettingsForm, self).load() # Load the cache settings. cache_backend_info = self.siteconfig.get('cache_backend') cache_backend = ( normalize_cache_backend(cache_backend_info, DEFAULT_FORWARD_CACHE_ALIAS) or normalize_cache_backend(cache_backend_info)) cache_backend_path = cache_backend['BACKEND'] cache_type = 'custom' for _cache_type, backend_info in self._cache_backends.items(): if (cache_backend_path == backend_info['backend_cls_path'] or cache_backend_path in backend_info.get( 'legacy_backend_cls_paths', [])): cache_type = _cache_type break cache_type_choices = [ (backend_id, backend_info['name']) for backend_id, backend_info in self._cache_backends.items() if backend_info.get('available', True) ] if cache_type == 'custom': cache_type_choices.append(('custom', ugettext('Custom'))) cache_type_field = self.fields['cache_type'] cache_type_field.choices = tuple(cache_type_choices) cache_type_field.initial = cache_type if cache_type in self.cache_backend_forms: self.cache_backend_forms[cache_type].load(cache_backend) # 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() # 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): """Load settings from the form. This will populate initial fields based on the site configuration. It takes care to transition legacy (<= Review Board 1.7) cache backends, if still used in production, to a modern configuration. """ domain_method = self.siteconfig.get('site_domain_method') site = Site.objects.get_current() # Load the rest of the settings from the form. super(GeneralSettingsForm, self).load() # Load the cache settings. cache_backend_info = self.siteconfig.get('cache_backend') cache_backend = ( normalize_cache_backend(cache_backend_info, DEFAULT_FORWARD_CACHE_ALIAS) or normalize_cache_backend(cache_backend_info)) 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', ugettext('Local memory cache')), ) if cache_type == 'custom': self.fields['cache_type'].choices += ( ('custom', ugettext('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.update( { DEFAULT_FORWARD_CACHE_ALIAS: ( normalize_cache_backend(value, DEFAULT_FORWARD_CACHE_ALIAS) or normalize_cache_backend(value) ), DEFAULT_CACHE_ALIAS: { "BACKEND": "%s.%s" % (ForwardingCacheBackend.__module__, ForwardingCacheBackend.__name__), "LOCATION": DEFAULT_FORWARD_CACHE_ALIAS, }, } ) from django.core.cache import cache if isinstance(cache, ForwardingCacheBackend): cache.reset_backend()
def _set_cache_backend(settings, key, value): settings.CACHES.update({ DEFAULT_FORWARD_CACHE_ALIAS: (normalize_cache_backend(value, DEFAULT_FORWARD_CACHE_ALIAS) or normalize_cache_backend(value)), DEFAULT_CACHE_ALIAS: { 'BACKEND': '%s.%s' % (ForwardingCacheBackend.__module__, ForwardingCacheBackend.__name__), 'LOCATION': DEFAULT_FORWARD_CACHE_ALIAS, }, }) from django.core.cache import cache if isinstance(cache, ForwardingCacheBackend): cache.reset_backend()
def load(self): """Load the form.""" domain_method = self.siteconfig.get("site_domain_method") site = Site.objects.get_current() # Load the rest of the settings from the form. super(GeneralSettingsForm, self).load() # Load the cache settings. cache_backend_info = self.siteconfig.get('cache_backend') cache_backend = ( normalize_cache_backend(cache_backend_info, DEFAULT_FORWARD_CACHE_ALIAS) or normalize_cache_backend(cache_backend_info)) 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): """Set the default cache backend. This will set the default cache backend to use Djblets's :py:class:`~djblets.cache.forwarding_backend.ForwardingCacheBackend`, and use that to forward on to the provided cache backend. The new cache settings will be instantly usable by the application without having to restart. Args: settings (django.conf.LazySettings): The Django settings object. key (unicode, unused): The settings key (``CACHES``). value (object): The cache backend settings. This may be a legacy URI or a dictionary containing cache backend information. """ settings.CACHES.update({ DEFAULT_FORWARD_CACHE_ALIAS: (normalize_cache_backend(value, DEFAULT_FORWARD_CACHE_ALIAS) or normalize_cache_backend(value)), DEFAULT_CACHE_ALIAS: { 'BACKEND': '%s.%s' % (ForwardingCacheBackend.__module__, ForwardingCacheBackend.__name__), 'LOCATION': DEFAULT_FORWARD_CACHE_ALIAS, }, }) from django.core.cache import cache if isinstance(cache, ForwardingCacheBackend): cache.reset_backend()
def _set_cache_backend(settings, key, value): """Set the default cache backend. This will set the default cache backend to use Djblets's :py:class:`~djblets.cache.forwarding_backend.ForwardingCacheBackend`, and use that to forward on to the provided cache backend. The new cache settings will be instantly usable by the application without having to restart. Args: settings (django.conf.LazySettings): The Django settings object. key (unicode, unused): The settings key (``CACHES``). value (object): The cache backend settings. This may be a legacy URI or a dictionary containing cache backend information. """ settings.CACHES.update({ DEFAULT_FORWARD_CACHE_ALIAS: ( normalize_cache_backend(value, DEFAULT_FORWARD_CACHE_ALIAS) or normalize_cache_backend(value)), DEFAULT_CACHE_ALIAS: { 'BACKEND': '%s.%s' % (ForwardingCacheBackend.__module__, ForwardingCacheBackend.__name__), 'LOCATION': DEFAULT_FORWARD_CACHE_ALIAS, }, }) from django.core.cache import cache if isinstance(cache, ForwardingCacheBackend): cache.reset_backend()
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)