djblets.siteconfig.django_settings¶
Utilities for going between SiteConfiguration and Django settings.
- class SiteConfigurationMappingDynamicValue(_typename, _fields=None, /, **kwargs)¶
Bases:
TypedDict
A dynamic value for serializing/deserializing siteconfig values.
New in version 3.1.
- deserialize_func: NotRequired[Callable[[SiteConfigurationSettingsValue], SiteConfigurationSettingsValue]]¶
A function for deserializing data from siteconfig settings.
- Type:
callable
- setter: NotRequired[Callable[[LazySettings, str, object], None]]¶
A function for setting data in Django.
- Type:
callable
- __annotations__ = {'deserialize_func': ForwardRef('NotRequired[Callable[[SiteConfigurationSettingsValue], SiteConfigurationSettingsValue]]'), 'key': ForwardRef('str'), 'setter': ForwardRef('NotRequired[Callable[[LazySettings, str, object], None]]')}¶
- static __new__(cls, _typename, _fields=None, /, **kwargs)¶
- __optional_keys__ = frozenset({})¶
- __orig_bases__ = (<class 'typing_extensions.TypedDict'>,)¶
- __required_keys__ = frozenset({'deserialize_func', 'key', 'setter'})¶
- __total__ = True¶
- SiteConfigurationSettingsMap¶
A dictionary mapping siteconfig keys to Django serialization information.
New in version 3.1.
alias of
Dict
[str
,Union
[str
,SiteConfigurationMappingDynamicValue
]]
- get_django_settings_map() Dict[str, Union[str, SiteConfigurationMappingDynamicValue]] ¶
Return a map of customizable Django settings.
These maps are passed to other functions, like
generate_defaults()
andapply_django_settings()
. Consumers can make their own settings map based on this with additional settings they want to provide.Each entry maps a siteconfig settings key to either a Django settings key or detailed information on serializing/deserializing a Django setting.
An entry with detailed information represents that as a dictionary containing the following fields:
- Keys:
key (
str
) – The Django settings key.deserialize_func (
callable
, optional) – A function taking the value from the siteconfig and returning a value usable in Django settings.setter (
callable
, optional) – A function taking the Django settings object, the Django settings key, and the new value from the siteconfig (after going throughdeserialize_func
, if provided). This will set the value in Django’s settings object.
- Returns:
The resulting settings map. This is generated once and cached for future calls.
- Return type:
- generate_defaults(settings_map: SiteConfigurationSettingsMap) SiteConfigurationSettings ¶
Return a dictionary of siteconfig defaults for Django settings.
This will iterate through the provided settings map and return a dictionary mapping a siteconfig settings key to the value from Django’s settings (if one is found).
- Parameters:
settings_map (
dict
) – A settings map, generated fromget_django_settings_map()
or a similar function.- Returns:
A dictionary of siteconfig defaults.
- Return type:
- get_locale_defaults() SiteConfigurationSettings ¶
Return a dictionary of siteconfig defaults for Django locale settings.
The generated defaults are specific to the values in
locale_settings_map
.- Returns:
A dictionary of siteconfig defaults.
- Return type:
- get_mail_defaults() SiteConfigurationSettings ¶
Return a dictionary of siteconfig defaults for Django e-mail settings.
The generated defaults are specific to the values in
mail_settings_map
.- Returns:
A dictionary of siteconfig defaults.
- Return type:
- get_site_defaults() SiteConfigurationSettings ¶
Return a dictionary of siteconfig defaults for Django site settings.
The generated defaults are specific to the values in
site_settings_map
.- Returns:
A dictionary of siteconfig defaults.
- Return type:
- get_cache_defaults() SiteConfigurationSettings ¶
Return a dictionary of siteconfig defaults for Django caching settings.
The generated defaults are specific to the values in
cache_settings_map
.- Returns:
A dictionary of siteconfig defaults.
- Return type:
- get_django_defaults() SiteConfigurationSettings ¶
Return a dictionary of siteconfig defaults for Django settings.
The generated defaults are specific to the values returned by
get_django_settings_map()
.- Returns:
A dictionary of siteconfig defaults.
- Return type:
- apply_django_settings(siteconfig: SiteConfiguration, settings_map: Optional[Dict[str, Union[str, SiteConfigurationMappingDynamicValue]]] = None) None ¶
Apply Django settings stored in the site configuration.
This takes a siteconfiguration storing Django settings and a settings map, applying each of the settings to Django. Setting will generally be stored in the Django settings object, but some settings will be specially applied based on their rules in the settings map.
- Parameters:
siteconfig (
djblets.siteconfig.models.SiteConfiguration
) – The site configuration containing the Django settings to apply.settings_map (
dict
, optional) –A map of siteconfig keys to Django settings information. See
get_django_settings_map()
for details.If not provided, the result of
get_django_settings_map()
will be used.