djblets.siteconfig.models¶
Database models for storing site configuration.
- class SiteConfigSettingsWrapper(siteconfig)[source]¶
Wraps the settings for a SiteConfiguration.
This is used by the context processor for templates to wrap accessing settings data, properly returning defaults.
- class SiteConfiguration(*args, **kwargs)[source]¶
Stored version and settings data for a Django site.
This stores dynamic settings for a site, along with version information, allowing the application to alter and apply/synchronize settings across threads, processes, and servers without restarting the server.
Consumers should not create or fetch their own instance of this class through standard Django query functions. Instead, they should use
SiteConfiguration.objects.get_current()
instead. See the documentation for that method for details on how to safely look up and use site configuration.- classmethod add_global_defaults(defaults_dict)[source]¶
Add a dictionary of global defaults for settings.
These defaults will be used when calling
get()
for any setting not stored. Defaults registered for a specific site configuration take precedent over global defaults.- Parameters
default_dict (dict) – A dictionary of defaults, mapping siteconfig settings keys to JSON-serializable values.
- classmethod add_global_default(key, default_value)[source]¶
Add a global default value for a settings key.
The default will be used when calling
get()
for this key, if a value is not stored. Defaults registered for a specific site configuration take precedent over global defaults.- Parameters
key (unicode) – The settings key to set the default for.
default_value (object) – The value to set as the default.
- classmethod remove_global_default(key)[source]¶
Remove a global default value for a settings key.
- Parameters
key (unicode) – The settings key to remove the default for.
- classmethod clear_global_defaults()[source]¶
Clear all default values for this site configuration.
This will clear only global defaults. This will not affect defaults registered on specific site configurations.
- classmethod get_global_defaults()[source]¶
Return all global defaults for settings.
- Returns
A dictionary of all registered global defaults for settings.
- Return type
- get(key, default=None)[source]¶
Return the value for a setting.
If the setting is not found, the default value will be returned. This is represented by the default parameter, if passed in, or a global default (from
add_default()
) if set.If no default is available,
None
will be returned.
- set(key, value)[source]¶
Set a value for a setting.
The setting will be stored locally until the model is saved, at which point it will be synchronized with other processes/servers.
- Parameters
key (unicode) – The key for the setting.
value (object) – The JSON-serializable object to store.
- add_defaults(defaults_dict)[source]¶
Add a dictionary of defaults for settings.
These defaults will be used when calling
get()
for any setting not stored. These will only be registered for this site configuration, and will not be registered for global defaults.- Parameters
default_dict (dict) – A dictionary of defaults, mapping siteconfig settings keys to JSON-serializable values.
- add_default(key, default_value)[source]¶
Add a default value for a settings key.
The default will be used when calling
get()
for this key, if a value is not stored. This will only be registered for this site configuration, and will not be registered for global defaults.- Parameters
key (unicode) – The settings key to set the default for.
default_value (object) – The value to set as the default.
- remove_default(key)[source]¶
Remove a default value on this site configuration.
This will remove only defaults registered on this site configuration. This does not affect global defaults.
- Parameters
key (unicode) – The settings key to remove the default for.
- clear_defaults()[source]¶
Clear all default values for this site configuration.
This will clear only defaults registered on this site configuration. This does not affect global defaults.
- get_defaults()[source]¶
Return all defaults for this site configuration.
This will return only defaults registered on this site configuration. The result does not include global defaults.
- Returns
A dictionary of all registered defaults for settings.
- Return type
- is_expired()[source]¶
Return whether or not this SiteConfiguration is expired.
If the configuration is expired, it will need to be reloaded before accessing any settings.
- Returns
Whether or not the current state is expired.
- Return type