|
@@ -48,7 +48,8 @@ class SettingValidator(object):
|
48
|
48
|
if self.__none_is_valid and value is None:
|
49
|
49
|
return None
|
50
|
50
|
try:
|
51
|
|
- return self._validators[self.__name](value, **self._opt_args)
|
|
51
|
+ ret = self._validators[self.__name](value, **self._opt_args)
|
|
52
|
+ return ret
|
52
|
53
|
except Exception as e:
|
53
|
54
|
raise SettingsValidationError(e)
|
54
|
55
|
|
|
@@ -250,10 +251,13 @@ def emfield_val(value):
|
250
|
251
|
#Able to check that the value is a plugin and if it is of a specific type
|
251
|
252
|
def plugin_validator(value, ptype = None):
|
252
|
253
|
from lodel.plugin.hooks import LodelHook
|
|
254
|
+ value = copy.copy(value)
|
253
|
255
|
@LodelHook('lodel2_dyncode_bootstraped')
|
254
|
256
|
def plugin_type_checker(hookname, caller, payload):
|
255
|
257
|
from lodel.plugin.plugins import Plugin
|
256
|
258
|
from lodel.plugin.exceptions import PluginError
|
|
259
|
+ if value is None:
|
|
260
|
+ return
|
257
|
261
|
try:
|
258
|
262
|
plugin = Plugin.get(value)
|
259
|
263
|
except PluginError:
|
|
@@ -266,7 +270,13 @@ named '%s' that is a '%s' plugin"
|
266
|
270
|
msg %= (ptype, value, plugin._type_conf_name)
|
267
|
271
|
raise SettingsValidationError(msg)
|
268
|
272
|
return value
|
269
|
|
-
|
|
273
|
+
|
|
274
|
+def custom_list_validator(value, validator_name, validator_kwargs = None):
|
|
275
|
+ validator_kwargs = dict() if validator_kwargs is None else validator_kwargs
|
|
276
|
+ validator = SettingValidator(validator_name, **validator_kwargs)
|
|
277
|
+ for item in value.split():
|
|
278
|
+ validator(item)
|
|
279
|
+ return value.split()
|
270
|
280
|
|
271
|
281
|
#
|
272
|
282
|
# Default validators registration
|
|
@@ -277,6 +287,11 @@ SettingValidator.register_validator(
|
277
|
287
|
plugin_validator,
|
278
|
288
|
'plugin name & type validator')
|
279
|
289
|
|
|
290
|
+SettingValidator.register_validator(
|
|
291
|
+ 'custom_list',
|
|
292
|
+ custom_list_validator,
|
|
293
|
+ 'A list validator that takes a "validator_name" as argument')
|
|
294
|
+
|
280
|
295
|
SettingValidator.register_validator(
|
281
|
296
|
'dummy',
|
282
|
297
|
lambda value:value,
|