Jump to >

This documentation covers Djblets 2.0. You can see the latest Djblets documentation or all other versions.

djblets.siteconfig.managers

Model and cache management for SiteConfiguration.

class SiteConfigurationManager[source]

Bases: django.db.models.manager.Manager

Manages cached instances of a SiteConfiguration.

This provides functions for retrieving the current SiteConfiguration instance and working with cache expiration. Consumers are expected to use get_current() to retrieve their instance, and are also expected to use the SettingsMiddleware to manage expiration between server processes.

get_current()[source]

Return the site configuration for the active site.

Multiple calls to this method for the same Site will return the same instance, as long as the old instance has not expired. Callers should not store the result of this method, as it may not be valid for long.

Returns:The current site configuration for the active site.
Return type:djblets.siteconfig.models.SiteConfiguration
Raises:django.core.exceptions.ImproperlyConfigured – Site information wasn’t configured in Django.
get_for_site_id(site_id)[source]

Return the site configuration for a specific site ID.

Multiple calls to this method for the same Site will return the same instance, as long as the old instance has not expired. Callers should not store the result of this method, as it may not be valid for long.

Parameters:site (int) – The ID of the site to retrieve the configuration for.
Returns:The current site configuration for the specified site.
Return type:djblets.siteconfig.models.SiteConfiguration
clear_cache()[source]

Clear the entire SiteConfiguration cache.

The next call to get_current() for any Site will query the database.

check_expired()[source]

Check whether any SiteConfigurations have expired.

If a SiteConfiguration has expired (another process/server has saved a more recent version), this method will expire the cache for the old version.

If there are any listeners for the siteconfig_reloaded signal, a new SiteConfiguration instance will be immediately loaded and the signal will fire. Otherwise, a new instance will not be loaded right away.

This should be called on each HTTP request. It’s recommended that consumers use SettingsMiddleware to do this. It can also be called manually for long-living processes that aren’t bound to HTTP requests.

Changed in version 1.0.3: The siteconfig_reloaded signal is now emitted with a newly-fetched instance if there are any listeners.

__slotnames__ = [][source]