mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Merge pull request #195 from jazzband/updated_signal
Added the old value to the config_updated signal
This commit is contained in:
commit
6da21af5ae
4 changed files with 7 additions and 5 deletions
|
|
@ -77,6 +77,7 @@ class DatabaseBackend(Backend):
|
|||
return value
|
||||
|
||||
def set(self, key, value):
|
||||
old_value = self.get(key)
|
||||
constance, created = self._model._default_manager.get_or_create(
|
||||
key=self.add_prefix(key), defaults={'value': value}
|
||||
)
|
||||
|
|
@ -87,7 +88,7 @@ class DatabaseBackend(Backend):
|
|||
self._cache.set(key, value)
|
||||
|
||||
signals.config_updated.send(
|
||||
sender=config, updated_key=key, new_value=value
|
||||
sender=config, key=key, old_value=old_value, new_value=value
|
||||
)
|
||||
|
||||
def clear(self, sender, instance, created, **kwargs):
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ class RedisBackend(Backend):
|
|||
yield key, loads(value)
|
||||
|
||||
def set(self, key, value):
|
||||
old_value = self.get(key)
|
||||
self._rd.set(self.add_prefix(key), dumps(value))
|
||||
signals.config_updated.send(
|
||||
sender=config, updated_key=key, new_value=value
|
||||
sender=config, key=key, old_value=old_value, new_value=value
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import django.dispatch
|
||||
|
||||
config_updated = django.dispatch.Signal(
|
||||
providing_args=['updated_key', 'new_value']
|
||||
providing_args=['key', 'old_value', 'new_value']
|
||||
)
|
||||
|
|
|
|||
|
|
@ -81,8 +81,8 @@ You can use it as:
|
|||
from constance.signals import config_updated
|
||||
|
||||
@receiver(config_updated)
|
||||
def constance_updated(sender, updated_key, new_value, **kwargs):
|
||||
print(sender, updated_key, new_value)
|
||||
def constance_updated(sender, key, old_value, new_value, **kwargs):
|
||||
print(sender, key, old_value, new_value)
|
||||
|
||||
The sender is the ``config`` object, and the ``updated_key`` and ``new_value``
|
||||
are the ones just changed.
|
||||
|
|
|
|||
Loading…
Reference in a new issue