mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 10:57:35 -02:30
Merge pull request #4008 from cchurch/conf-jsonfield-fixes
Fix configure Tower in Tower to work with updated django-jsonfield.
This commit is contained in:
@@ -314,9 +314,6 @@ class Command(BaseCommand):
|
|||||||
self.stdout.write(' No settings to migrate!')
|
self.stdout.write(' No settings to migrate!')
|
||||||
for name, db_value in to_migrate.items():
|
for name, db_value in to_migrate.items():
|
||||||
display_value = json.dumps(db_value, indent=4)
|
display_value = json.dumps(db_value, indent=4)
|
||||||
# Always encode "raw" strings as JSON.
|
|
||||||
if isinstance(db_value, basestring):
|
|
||||||
db_value = json.dumps(db_value)
|
|
||||||
setting = Setting.objects.filter(key=name, user__isnull=True).order_by('pk').first()
|
setting = Setting.objects.filter(key=name, user__isnull=True).order_by('pk').first()
|
||||||
action = 'No Change'
|
action = 'No Change'
|
||||||
if not setting:
|
if not setting:
|
||||||
|
|||||||
@@ -14,11 +14,6 @@ def copy_tower_settings(apps, schema_editor):
|
|||||||
# LICENSE is stored as a string; convert it to a dict.
|
# LICENSE is stored as a string; convert it to a dict.
|
||||||
if tower_setting.key == 'LICENSE':
|
if tower_setting.key == 'LICENSE':
|
||||||
value = json.loads(value)
|
value = json.loads(value)
|
||||||
# Anything else (e.g. TOWER_URL_BASE) that is stored as a string
|
|
||||||
# needs to be converted to a JSON-encoded string to work with the
|
|
||||||
# JSON field.
|
|
||||||
elif tower_setting.value_type == 'string':
|
|
||||||
value = json.dumps(value)
|
|
||||||
setting, created = Setting.objects.get_or_create(
|
setting, created = Setting.objects.get_or_create(
|
||||||
key=tower_setting.key,
|
key=tower_setting.key,
|
||||||
user=tower_setting.user,
|
user=tower_setting.user,
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ class Setting(CreatedModifiedModel):
|
|||||||
)
|
)
|
||||||
value = JSONField(
|
value = JSONField(
|
||||||
null=True,
|
null=True,
|
||||||
# FIXME: Enable when we upgrade to JSONField with support:
|
|
||||||
# load_kwargs={'object_pairs_hook': collections.OrderedDict},
|
|
||||||
)
|
)
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
'auth.User',
|
'auth.User',
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
# Python
|
# Python
|
||||||
import contextlib
|
import contextlib
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@@ -142,16 +141,18 @@ class SettingsWrapper(UserSettingsHolder):
|
|||||||
def _get_local(self, name):
|
def _get_local(self, name):
|
||||||
self._preload_cache()
|
self._preload_cache()
|
||||||
cache_key = Setting.get_cache_key(name)
|
cache_key = Setting.get_cache_key(name)
|
||||||
value = cache.get(cache_key, empty)
|
cache_value = cache.get(cache_key, empty)
|
||||||
logger.debug('cache get(%r, %r) -> %r', cache_key, empty, value)
|
logger.debug('cache get(%r, %r) -> %r', cache_key, empty, cache_value)
|
||||||
if value == SETTING_CACHE_NOTSET:
|
if cache_value == SETTING_CACHE_NOTSET:
|
||||||
value = empty
|
value = empty
|
||||||
elif value == SETTING_CACHE_NONE:
|
elif cache_value == SETTING_CACHE_NONE:
|
||||||
value = None
|
value = None
|
||||||
elif value == SETTING_CACHE_EMPTY_LIST:
|
elif cache_value == SETTING_CACHE_EMPTY_LIST:
|
||||||
value = []
|
value = []
|
||||||
elif value == SETTING_CACHE_EMPTY_DICT:
|
elif cache_value == SETTING_CACHE_EMPTY_DICT:
|
||||||
value = {}
|
value = {}
|
||||||
|
else:
|
||||||
|
value = cache_value
|
||||||
field = settings_registry.get_setting_field(name)
|
field = settings_registry.get_setting_field(name)
|
||||||
if value is empty:
|
if value is empty:
|
||||||
setting = None
|
setting = None
|
||||||
@@ -159,9 +160,6 @@ class SettingsWrapper(UserSettingsHolder):
|
|||||||
setting = Setting.objects.filter(key=name, user__isnull=True).order_by('pk').first()
|
setting = Setting.objects.filter(key=name, user__isnull=True).order_by('pk').first()
|
||||||
if setting:
|
if setting:
|
||||||
value = setting.value
|
value = setting.value
|
||||||
# If None implies not set, convert when reading the value.
|
|
||||||
if value is None and SETTING_CACHE_NOTSET == SETTING_CACHE_NONE:
|
|
||||||
value = SETTING_CACHE_NOTSET
|
|
||||||
else:
|
else:
|
||||||
value = SETTING_CACHE_NOTSET
|
value = SETTING_CACHE_NOTSET
|
||||||
if SETTING_CACHE_DEFAULTS:
|
if SETTING_CACHE_DEFAULTS:
|
||||||
@@ -169,8 +167,12 @@ class SettingsWrapper(UserSettingsHolder):
|
|||||||
value = field.get_default()
|
value = field.get_default()
|
||||||
except SkipField:
|
except SkipField:
|
||||||
pass
|
pass
|
||||||
logger.debug('cache set(%r, %r, %r)', cache_key, self._get_cache_value(value), SETTING_CACHE_TIMEOUT)
|
# If None implies not set, convert when reading the value.
|
||||||
cache.set(cache_key, self._get_cache_value(value), SETTING_CACHE_TIMEOUT)
|
if value is None and SETTING_CACHE_NOTSET == SETTING_CACHE_NONE:
|
||||||
|
value = SETTING_CACHE_NOTSET
|
||||||
|
if cache_value != value:
|
||||||
|
logger.debug('cache set(%r, %r, %r)', cache_key, self._get_cache_value(value), SETTING_CACHE_TIMEOUT)
|
||||||
|
cache.set(cache_key, self._get_cache_value(value), SETTING_CACHE_TIMEOUT)
|
||||||
if value == SETTING_CACHE_NOTSET and not SETTING_CACHE_DEFAULTS:
|
if value == SETTING_CACHE_NOTSET and not SETTING_CACHE_DEFAULTS:
|
||||||
try:
|
try:
|
||||||
value = field.get_default()
|
value = field.get_default()
|
||||||
@@ -218,9 +220,6 @@ class SettingsWrapper(UserSettingsHolder):
|
|||||||
logger.exception('Unable to assign value "%r" to setting "%s".', value, name, exc_info=True)
|
logger.exception('Unable to assign value "%r" to setting "%s".', value, name, exc_info=True)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
# Always encode "raw" strings as JSON.
|
|
||||||
if isinstance(db_value, basestring):
|
|
||||||
db_value = json.dumps(db_value)
|
|
||||||
setting = Setting.objects.filter(key=name, user__isnull=True).order_by('pk').first()
|
setting = Setting.objects.filter(key=name, user__isnull=True).order_by('pk').first()
|
||||||
if not setting:
|
if not setting:
|
||||||
setting = Setting.objects.create(key=name, user=None, value=db_value)
|
setting = Setting.objects.create(key=name, user=None, value=db_value)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
# Python
|
# Python
|
||||||
import collections
|
import collections
|
||||||
import json
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
@@ -100,9 +99,6 @@ class SettingSingletonDetail(RetrieveUpdateDestroyAPIView):
|
|||||||
if key == 'LICENSE':
|
if key == 'LICENSE':
|
||||||
continue
|
continue
|
||||||
setattr(serializer.instance, key, value)
|
setattr(serializer.instance, key, value)
|
||||||
# Always encode "raw" strings as JSON.
|
|
||||||
if isinstance(value, basestring):
|
|
||||||
value = json.dumps(value)
|
|
||||||
setting = settings_qs.filter(key=key).order_by('pk').first()
|
setting = settings_qs.filter(key=key).order_by('pk').first()
|
||||||
if not setting:
|
if not setting:
|
||||||
setting = Setting.objects.create(key=key, user=user, value=value)
|
setting = Setting.objects.create(key=key, user=user, value=value)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ __all__ = ['AutoOneToOneField', 'ImplicitRoleField', 'JSONField']
|
|||||||
class JSONField(upstream_JSONField):
|
class JSONField(upstream_JSONField):
|
||||||
|
|
||||||
def from_db_value(self, value, expression, connection, context):
|
def from_db_value(self, value, expression, connection, context):
|
||||||
if value in ['', None]:
|
if value in {'', None} and not self.null:
|
||||||
return {}
|
return {}
|
||||||
return super(JSONField, self).from_db_value(value, expression, connection, context)
|
return super(JSONField, self).from_db_value(value, expression, connection, context)
|
||||||
|
|
||||||
|
|||||||
@@ -426,6 +426,12 @@ class LDAPTeamMapField(fields.DictField):
|
|||||||
|
|
||||||
class RADIUSSecretField(fields.CharField):
|
class RADIUSSecretField(fields.CharField):
|
||||||
|
|
||||||
|
def run_validation(self, data=empty):
|
||||||
|
value = super(RADIUSSecretField, self).run_validation(data)
|
||||||
|
if isinstance(value, unicode):
|
||||||
|
value = value.encode('utf-8')
|
||||||
|
return value
|
||||||
|
|
||||||
def to_internal_value(self, value):
|
def to_internal_value(self, value):
|
||||||
value = super(RADIUSSecretField, self).to_internal_value(value)
|
value = super(RADIUSSecretField, self).to_internal_value(value)
|
||||||
if isinstance(value, unicode):
|
if isinstance(value, unicode):
|
||||||
|
|||||||
Reference in New Issue
Block a user