openedx.core.djangoapps.site_configuration package#
Subpackages#
Submodules#
openedx.core.djangoapps.site_configuration.context_processors module#
Django template context processors.
- openedx.core.djangoapps.site_configuration.context_processors.configuration_context(request)#
Configuration context for django templates.
openedx.core.djangoapps.site_configuration.helpers module#
Helpers methods for site configuration.
- openedx.core.djangoapps.site_configuration.helpers.get_all_orgs()#
This returns all of the orgs that are considered in site configurations. This can be used, for example, to do filtering.
- Returns:
A set of all organizations present in the site configuration.
- openedx.core.djangoapps.site_configuration.helpers.get_configuration_dict(name, default=None)#
Returns a dictionary product after merging the current site’s configuration and the default value.
- Parameters:
name (str) – Name of the configuration dict to retrieve.
default (dict) – default dict containing key-value pairs of default values.
- Returns:
Configuration value for the given key or returns {} if configuration is not enabled.
- openedx.core.djangoapps.site_configuration.helpers.get_configuration_value(name, default=None)#
Return Configuration value for the key specified as name argument.
- Parameters:
name (str) – Name of the key for which to return configuration value.
default – default value tp return if key is not found in the configuration
- Returns:
Configuration value for the given key or returns None if configuration is not enabled.
- openedx.core.djangoapps.site_configuration.helpers.get_current_site_configuration()#
Return configuration for the current site.
- Returns:
SiteConfiguration instance associated with the current site.
- Return type:
(openedx.core.djangoapps.site_configuration.models.SiteConfiguration)
- openedx.core.djangoapps.site_configuration.helpers.get_current_site_configuration_values(default=None)#
Returns SiteConfiguration.site_values for current site. :param default: default value ({} if not specified) to return if site configuration is not available. :type default: dict
- Returns:
(dict) Site Configuration value for the current site or default
- openedx.core.djangoapps.site_configuration.helpers.get_current_site_orgs()#
This returns the orgs configured in site configuration for the current site.
- Returns:
A list of organization names.
- Return type:
list
- openedx.core.djangoapps.site_configuration.helpers.get_dict(name, default=None)#
Returns a dictionary product after merging configuration and the default value.
- Parameters:
name (str) – Name of the configuration dict to retrieve.
default (dict) – default dict containing key-value pairs of default values.
- Returns:
Configuration value for the given key or returns {} if configuration not found.
- openedx.core.djangoapps.site_configuration.helpers.get_value(val_name, default=None, **kwargs)#
Return configuration value for the key specified as name argument.
- Parameters:
val_name (str) – Name of the key for which to return configuration value.
default – default value tp return if key is not found in the configuration
- Returns:
Configuration value for the given key.
- openedx.core.djangoapps.site_configuration.helpers.get_value_for_org(org, val_name, default=None)#
This returns a configuration value for a site configuration which has an org_filter that matches with the argument.
- Parameters:
org (str) – Course org filter, this value will be used to filter out the correct site configuration.
val_name (str) – Name of the key for which to return configuration value.
default – default value to return if key is not present in the configuration
- Returns:
Configuration value for the given key.
- openedx.core.djangoapps.site_configuration.helpers.has_configuration_override(name)#
Returns True/False whether a Site Configuration has a definition for the specified key.
- Parameters:
name (str) – Name of the configuration dict to retrieve.
- Returns:
True if given key is present in the configuration.
- Return type:
(bool)
- openedx.core.djangoapps.site_configuration.helpers.has_override_value(name)#
Returns True/False whether configuration has a definition for the specified key.
- Parameters:
name (str) – Name of the configuration dict to retrieve.
- Returns:
True if given key is present in the configuration.
- Return type:
(bool)
- openedx.core.djangoapps.site_configuration.helpers.is_site_configuration_enabled()#
Returns True is there is SiteConfiguration instance associated with the current site and it is enabled, otherwise returns False.
- Returns:
True if SiteConfiguration is present and enabled, False otherwise
- Return type:
(bool)
- openedx.core.djangoapps.site_configuration.helpers.page_title_breadcrumbs(*crumbs, **kwargs)#
This function creates a suitable page title in the form: Specific | Less Specific | General | edX It will output the correct platform name for the request. Pass in a separator kwarg to override the default of “ | “
openedx.core.djangoapps.site_configuration.middleware module#
This file contains Django middleware related to the site_configuration app.
- class openedx.core.djangoapps.site_configuration.middleware.SessionCookieDomainOverrideMiddleware(get_response)#
Bases:
MiddlewareMixinSpecial case middleware which should be at the very end of the MIDDLEWARE list (so that it runs first on the process_response chain). This middleware will define a wrapper function for the set_cookie() function on the HttpResponse object, if the request is running in a middleware.
This wrapped set_cookie will change the SESSION_COOKIE_DOMAIN setting so that the cookie can be bound to a fully customized URL.
- process_response(__, response)#
Django middleware hook for process responses
openedx.core.djangoapps.site_configuration.models module#
Django models for site configurations.
- class openedx.core.djangoapps.site_configuration.models.SiteConfiguration(*args, **kwargs)#
Bases:
ModelModel for storing site configuration. These configuration override OpenEdx configurations and settings. e.g. You can override site name, logo image, favicon etc. using site configuration.
- Fields:
site (OneToOneField): one to one field relating each configuration to a single site site_values (JSONField): json field to store configurations for a site
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod get_all_orgs()#
This returns all of the orgs that are considered in site configurations, This can be used, for example, to do filtering.
- Returns:
A set of all organizations present in site configuration.
- classmethod get_configuration_for_org(org, select_related=None)#
This returns a SiteConfiguration object which has an org_filter that matches the supplied org
- Parameters:
org (str) – Org to use to filter SiteConfigurations
select_related (list or None) – A list of values to pass as arguments to select_related
- get_value(name, default=None)#
Return Configuration value for the key specified as name argument.
Function logs a message if configuration is not enabled or if there is an error retrieving a key.
- Parameters:
name (str) – Name of the key for which to return configuration value.
default – default value tp return if key is not found in the configuration
- Returns:
Configuration value for the given key or returns None if configuration is not enabled.
- classmethod get_value_for_org(org, name, default=None)#
This returns site configuration value which has an org_filter that matches what is passed in,
- Parameters:
org (str) – Course ord filter, this value will be used to filter out the correct site configuration.
name (str) – Name of the key for which to return configuration value.
default – default value tp return if key is not found in the configuration
- Returns:
Configuration value for the given key.
- classmethod has_org(org)#
Check if the given organization is present in any of the site configuration.
- Returns:
True if given organization is present in site configurations otherwise False.
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- site#
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.placeis aForwardOneToOneDescriptorinstance.
- site_id#
- site_values#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class openedx.core.djangoapps.site_configuration.models.SiteConfigurationHistory(*args, **kwargs)#
Bases:
TimeStampedModelThis is an archive table for SiteConfiguration, so that we can maintain a history of changes. Note that the site field is not unique in this model, compared to SiteConfiguration.
- Fields:
site (ForeignKey): foreign-key to django Site site_values (JSONField): json field to store configurations for a site
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- site#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- site_id#
- site_values#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- openedx.core.djangoapps.site_configuration.models.save_siteconfig_without_historical_record(siteconfig, *args, **kwargs)#
Save model without saving a historical record
Make sure you know what you’re doing before you use this method.
Note: this method is copied verbatim from django-simple-history.
- openedx.core.djangoapps.site_configuration.models.update_site_configuration_history(sender, instance, created, **kwargs)#
Add site configuration changes to site configuration history.
Recording history on updates and deletes can be skipped by first setting the skip_history_when_saving attribute on the instace, e.g.:
site_config.skip_history_when_saving = True site_config.save()
- Parameters:
sender – sender of the signal i.e. SiteConfiguration model
instance – SiteConfiguration instance associated with the current signal
created (bool) – True if a new record was created.
**kwargs – extra key word arguments
Module contents#
This app is used for creating/updating site’s configuration. This app encapsulate configuration related logic for sites and provides a way for sites to override default/system behavioural or presentation logic.
- Models:
- SiteConfiguration (models.Model):
This model contains configuration for a site and can be used to override OpenEdx configurations.
- Fields:
site (OneToOneField): one to one field relating each configuration to a single site values (JSONField): json field to store configurations for a site
- Usage:
configuration of each site would be available as configuration attribute to django site. If you want to access current site’s configuration simply access it as request.site.configuration.
- SiteConfigurationHistory (TimeStampedModel):
This model keeps a track of all the changes made to SiteConfiguration with time stamps.
- Fields:
site (ForeignKey): foreign-key to django Site values (JSONField): json field to store configurations for a site
- Usage:
configuration history of each site would be available as configuration_histories attribute to django site. If you want to access a list of current site’s configuration history simply access it as request.site.configuration_histories.all().