mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Send the config parameter as sender for the signal
This commit is contained in:
parent
1d746c080f
commit
bebc279edc
3 changed files with 17 additions and 10 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue