From bebc279edc9a76caa8d03cf435dec05a0bfd59db Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Thu, 15 Sep 2016 09:24:30 -0500 Subject: [PATCH] Send the config parameter as sender for the signal --- constance/backends/database/__init__.py | 9 +++++---- constance/backends/redisd.py | 6 ++++-- docs/index.rst | 12 ++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/constance/backends/database/__init__.py b/constance/backends/database/__init__.py index 7f7bef0..822531d 100644 --- a/constance/backends/database/__init__.py +++ b/constance/backends/database/__init__.py @@ -4,7 +4,7 @@ from django.core.exceptions import ImproperlyConfigured from django.db.models.signals import post_save from .. import Backend -from ... import settings, signals +from ... import settings, signals, config class DatabaseBackend(Backend): @@ -86,12 +86,13 @@ class DatabaseBackend(Backend): if self._cache: self._cache.set(key, value) - signals.config_updated.send(sender='constance', key=key, value=value) + signals.config_updated.send( + sender=config, updated_key=key, new_value=value + ) def clear(self, sender, instance, created, **kwargs): if self._cache and not created: - keys = [self.add_prefix(k) - for k in settings.CONFIG.keys()] + keys = [self.add_prefix(k) for k in settings.CONFIG.keys()] keys.append(self.add_prefix(self._autofill_cachekey)) self._cache.delete_many(keys) self.autofill() diff --git a/constance/backends/redisd.py b/constance/backends/redisd.py index 30a9e28..dbb2045 100644 --- a/constance/backends/redisd.py +++ b/constance/backends/redisd.py @@ -3,7 +3,7 @@ from django.utils import six from django.utils.six.moves import zip from . import Backend -from .. import settings, utils, signals +from .. import settings, utils, signals, config try: from cPickle import loads, dumps @@ -49,4 +49,6 @@ class RedisBackend(Backend): def set(self, key, value): self._rd.set(self.add_prefix(key), dumps(value)) - signals.config_updated.send(sender='constance', key=key, value=value) + signals.config_updated.send( + sender=config, updated_key=key, new_value=value + ) diff --git a/docs/index.rst b/docs/index.rst index 5c1ee77..9aa1533 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -81,11 +81,15 @@ You can use it as: from constance.signals import config_updated @receiver(config_updated) - def constance_updated(sender, key, value, **kwargs): - print(sender, key, value) + def constance_updated(sender, updated_key, new_value, **kwargs): + print(sender, updated_key, new_value) -In case you need it the sender is `constance`, and the key and value are -the ones just changed. +The sender is the `config` object, and the `updated_key` and `new_value` +are the ones just changed. + +This callback will get the `config` object as the first parameter so you +can have an isolated function where you can access the `config` object +without dealing with additional imports. Custom fields