def get_setting(self, app, name): """ Returns the current ``Configuration`` based on the app-label and the name of the setting. The ``Configuration`` object is cached in the bmf default cache connection (which should be shared throughout all instances) """ # We need a database connection, and thus the apps to be ready if not apps.ready: # pragma: no cover return None cache = caches[settings.CACHE_DEFAULT_CONNECTION] key = CACHE_KEY_TEMPLATE % (app, name) value = cache.get(key) if not value: from djangobmf.sites import site if not site.is_active: return None # check if the field exists field = site.get_setting_field(app, name) object, created = self.get_or_create(app_label=app, field_name=name) if created: object.value = json.dumps(field.initial) object.save() value = field.initial elif object.value: value = json.loads(object.value) cache.set(key, value) return value
def __init__(self, *args, **kwargs): super(ConfigForm, self).__init__(*args, **kwargs) self.fields[name] = site.get_setting_field(app_label, name)