mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Added signal on change, refs #158
This commit is contained in:
parent
90bf97c0a9
commit
94fabdf7c3
4 changed files with 12 additions and 5 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import django.dispatch
|
||||
from django.utils.functional import LazyObject
|
||||
|
||||
__version__ = '1.2.1'
|
||||
|
|
@ -10,4 +11,7 @@ class LazyConfig(LazyObject):
|
|||
from .base import Config
|
||||
self._wrapped = Config()
|
||||
|
||||
|
||||
config = LazyConfig()
|
||||
|
||||
updated_signal = django.dispatch.Signal(providing_args=['key', 'value'])
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from django.db.models import signals
|
||||
from django import VERSION
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
|
@ -22,11 +21,10 @@ class ConstanceConfig(AppConfig):
|
|||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
if ContentType._meta.installed and Permission._meta.installed:
|
||||
extra = {} if VERSION >= (1, 8) else {'name': 'config'}
|
||||
content_type, created = ContentType.objects.get_or_create(
|
||||
app_label='constance',
|
||||
model='config',
|
||||
**extra)
|
||||
)
|
||||
|
||||
permission, created = Permission.objects.get_or_create(
|
||||
name='Can change config',
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from django.db.models.signals import post_save
|
|||
|
||||
from .. import Backend
|
||||
from ... import settings
|
||||
from ... import updated_signal
|
||||
|
||||
|
||||
class DatabaseBackend(Backend):
|
||||
|
|
@ -25,8 +26,8 @@ class DatabaseBackend(Backend):
|
|||
if isinstance(self._cache, LocMemCache):
|
||||
raise ImproperlyConfigured(
|
||||
"The CONSTANCE_DATABASE_CACHE_BACKEND setting refers to a "
|
||||
"subclass of Django's local-memory backend (%r). Please set "
|
||||
"it to a backend that supports cross-process caching."
|
||||
"subclass of Django's local-memory backend (%r). Please "
|
||||
"set it to a backend that supports cross-process caching."
|
||||
% settings.DATABASE_CACHE_BACKEND)
|
||||
else:
|
||||
self._cache = None
|
||||
|
|
@ -86,6 +87,8 @@ class DatabaseBackend(Backend):
|
|||
if self._cache:
|
||||
self._cache.set(key, value)
|
||||
|
||||
updated_signal.send(sender='constance', key=key, value=value)
|
||||
|
||||
def clear(self, sender, instance, created, **kwargs):
|
||||
if self._cache and not created:
|
||||
keys = [self.add_prefix(k)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from django.utils.six.moves import zip
|
|||
|
||||
from . import Backend
|
||||
from .. import settings, utils
|
||||
from .. import updated_signal
|
||||
|
||||
try:
|
||||
from cPickle import loads, dumps
|
||||
|
|
@ -49,3 +50,4 @@ class RedisBackend(Backend):
|
|||
|
||||
def set(self, key, value):
|
||||
self._rd.set(self.add_prefix(key), dumps(value))
|
||||
updated_signal.send(sender='constance', key=key, value=value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue