mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
fixed imports, optional django dependency
This commit is contained in:
parent
fb016f2074
commit
24296bfe32
1 changed files with 7 additions and 5 deletions
|
|
@ -1,13 +1,16 @@
|
|||
import os
|
||||
import redis
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
try:
|
||||
from cPickle import loads, dumps
|
||||
except ImportError:
|
||||
from pickle import loads, dumps
|
||||
|
||||
def import_module(path):
|
||||
package, module = path.rsplit('.', 1)
|
||||
return getattr(__import__(package, None, None, [module]), module)
|
||||
|
||||
settings = import_module(os.getenv('CONSTANCE_SETTINGS_MODULE', 'django.conf.settings'))
|
||||
|
||||
|
||||
class Config(object):
|
||||
|
|
@ -15,8 +18,7 @@ class Config(object):
|
|||
def __init__(self):
|
||||
super(Config, self).__setattr__('_prefix', getattr(settings, 'CONSTANCE_PREFIX', 'constance:'))
|
||||
try:
|
||||
module, class_ = settings.CONSTANCE_CONNECTION_CLASS.rsplit('.')
|
||||
super(Config, self).__setattr__('_rd', getattr(import_module(module), class_)())
|
||||
super(Config, self).__setattr__('_rd', import_module(settings.CONSTANCE_CONNECTION_CLASS)())
|
||||
except AttributeError:
|
||||
super(Config, self).__setattr__('_rd', redis.Redis(**settings.CONSTANCE_CONNECTION))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue