Complete Cluster Scope settings scope read only support
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import absolute_import
|
||||
|
||||
from project_setup.api import register_setup
|
||||
|
||||
from .classes import SettingsNamespace, LocalScope
|
||||
from .classes import SettingsNamespace, LocalScope, ClusterScope
|
||||
from .links import link_settings
|
||||
|
||||
register_setup(link_settings)
|
||||
|
||||
7
apps/smart_settings/admin.py
Normal file
7
apps/smart_settings/admin.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import ClusterSetting
|
||||
|
||||
admin.site.register(ClusterSetting)
|
||||
@@ -41,7 +41,7 @@ class SettingsNamespace(object):
|
||||
|
||||
|
||||
# Scopes
|
||||
class SettingScope(object):
|
||||
class ScopeBase(object):
|
||||
def get_value(self):
|
||||
raise NotImplemented
|
||||
|
||||
@@ -52,10 +52,10 @@ class SettingScope(object):
|
||||
self.setting = setting
|
||||
|
||||
def get_full_name(self):
|
||||
return '%s_%s' % (self.setting.namespace.name, self.setting.name)
|
||||
return ('%s_%s' % (self.setting.namespace.name, self.setting.name)).upper()
|
||||
|
||||
|
||||
class LocalScope(SettingScope):
|
||||
class LocalScope(ScopeBase):
|
||||
"""
|
||||
Return the value of a config value from the local settings.py file
|
||||
"""
|
||||
@@ -72,12 +72,12 @@ class LocalScope(SettingScope):
|
||||
|
||||
def get_value(self):
|
||||
if not self.global_name:
|
||||
self.global_name = self.get_full_name().upper()
|
||||
self.global_name = self.get_full_name()
|
||||
|
||||
return getattr(settings, self.global_name)
|
||||
|
||||
|
||||
class ClusterScope(SettingScope):
|
||||
class ClusterScope(ScopeBase):
|
||||
"""
|
||||
Return the value of a config value from the local settings.py file
|
||||
"""
|
||||
@@ -93,11 +93,7 @@ class ClusterScope(SettingScope):
|
||||
return unicode(self.__unicode__())
|
||||
|
||||
def get_value(self):
|
||||
#if not self.global_name:
|
||||
# self.global_name = '%s_%s' % (self.setting.namespace.name.upper(), self.setting.name)
|
||||
#ClusterSetting.objects.
|
||||
return None
|
||||
return getattr(settings, self.global_name)
|
||||
return ClusterSetting.objects.get(name=self.get_full_name()).value
|
||||
|
||||
def register_setting(self, *args, **kwargs):
|
||||
super(ClusterScope, self).register_setting(*args, **kwargs)
|
||||
|
||||
34
apps/smart_settings/migrations/0001_initial.py
Normal file
34
apps/smart_settings/migrations/0001_initial.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding model 'ClusterSetting'
|
||||
db.create_table('smart_settings_clustersetting', (
|
||||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=64)),
|
||||
('value', self.gf('django.db.models.fields.TextField')(blank=True)),
|
||||
))
|
||||
db.send_create_signal('smart_settings', ['ClusterSetting'])
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting model 'ClusterSetting'
|
||||
db.delete_table('smart_settings_clustersetting')
|
||||
|
||||
|
||||
models = {
|
||||
'smart_settings.clustersetting': {
|
||||
'Meta': {'object_name': 'ClusterSetting'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'}),
|
||||
'value': ('django.db.models.fields.TextField', [], {'blank': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['smart_settings']
|
||||
0
apps/smart_settings/migrations/__init__.py
Normal file
0
apps/smart_settings/migrations/__init__.py
Normal file
Reference in New Issue
Block a user