Skip to content

mixins

django_spire.contrib.options.mixins

DEFAULT_OPTIONS = Options(sections=[]) module-attribute

OptionsModelMixin

Bases: Model

Source code in django_spire/contrib/options/mixins.py
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.options = Options.load_dict(self._options)

options = Options.load_dict(self._options) instance-attribute

Meta

abstract = True class-attribute instance-attribute

get_option

Source code in django_spire/contrib/options/mixins.py
def get_option(self, section_name: str, option_key: str):
    self._sync_options()
    return self.options.get_setting(section_name, option_key)

update_session

Source code in django_spire/contrib/options/mixins.py
def update_session(self, request):
    request.session['user_options'] = self.options.to_dict()

update_option

Source code in django_spire/contrib/options/mixins.py
def update_option(
        self,
        section_name: str,
        option_key: str,
        value: str | bool | int,
        commit=True
):
    self._sync_options()
    self.options.update_setting(section_name, option_key, value)
    self._options = self.options.to_dict()

    if commit:
        self.save()