Fix YAML quoting issues.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -93,9 +93,10 @@ class Setting(object):
|
||||
@classmethod
|
||||
def dump_data(cls):
|
||||
dictionary = {}
|
||||
|
||||
for setting in cls.get_all():
|
||||
if setting.quoted:
|
||||
dictionary[setting.global_name] = '{}'.format(setting.value)
|
||||
if isinstance(setting.value, Promise):
|
||||
dictionary[setting.global_name] = force_text(setting.value)
|
||||
else:
|
||||
dictionary[setting.global_name] = setting.value
|
||||
|
||||
@@ -169,9 +170,5 @@ class Setting(object):
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
# value is in YAML format
|
||||
if self.quoted:
|
||||
self.yaml = '\'{}\''.format(value)
|
||||
value = '\'{}\''.format(value)
|
||||
else:
|
||||
self.yaml = value
|
||||
self.raw_value = Setting.deserialize_value(value)
|
||||
|
||||
@@ -15,15 +15,25 @@ class SettingForm(forms.Form):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SettingForm, self).__init__(*args, **kwargs)
|
||||
self.fields['value'].help_text = self.initial['setting'].help_text
|
||||
self.fields['value'].initial = self.initial['setting'].serialized_value
|
||||
self.setting = self.initial['setting']
|
||||
self.fields['value'].help_text = self.setting.help_text
|
||||
self.fields['value'].initial = self.setting.serialized_value
|
||||
|
||||
def clean(self):
|
||||
quotes = ['"', "'"]
|
||||
|
||||
if self.setting.quoted:
|
||||
stripped = self.cleaned_data['value'].strip()
|
||||
|
||||
if stripped[0] not in quotes or stripped[-1] not in quotes:
|
||||
raise ValidationError(
|
||||
_(
|
||||
'Value must be properly quoted.'
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
yaml.safe_load(self.cleaned_data['value'])
|
||||
except yaml.YAMLError as exception:
|
||||
try:
|
||||
yaml.safe_load('{}'.format(self.cleaned_data['value']))
|
||||
except yaml.YAMLError as exception:
|
||||
raise ValidationError(
|
||||
_(
|
||||
|
||||
Reference in New Issue
Block a user