Browse Source

Merge branch 'newlodel' of git.labocleo.org:lodel2 into newlodel

prieto 8 years ago
parent
commit
ccff451d16
4 changed files with 24 additions and 33 deletions
  1. BIN
      examples/em_test.pickle
  2. 6
    3
      lodel/plugin/plugins.py
  3. 16
    28
      lodel/settings/validator.py
  4. 2
    2
      tests/datahandlers/test_boolean.py

BIN
examples/em_test.pickle View File


+ 6
- 3
lodel/plugin/plugins.py View File

@@ -793,9 +793,6 @@ with %s" % (custom_method._method_name, custom_method))
793 793
 #
794 794
 
795 795
 
796
-
797
-
798
-
799 796
 class SessionHandler(Plugin):
800 797
     __instance = None
801 798
 
@@ -806,3 +803,9 @@ class SessionHandler(Plugin):
806 803
         
807 804
     def __init__(self, plugin_name):
808 805
         super(Plugin, self).__init__(plugin_name)
806
+
807
+class InterfacePlugin(Plugin):
808
+    def __init__(self, plugin_name):
809
+        super(Plugin, self).__init__(plugin_name)
810
+
811
+        

+ 16
- 28
lodel/settings/validator.py View File

@@ -238,37 +238,25 @@ def emfield_val(value):
238 238
             msg = "Following field not found in class %s : %s"
239 239
             raise SettingsValidationError(msg % value)
240 240
     return value
241
-        
242
-def plugin_val(value):
243
-    #Late validation hook
244
-    @LodelHook('lodel2_dyncode_bootstraped')
245
-    def plugin_check(hookname, caller, payload):
246
-        from lodel import plugin
247
-        for inst in plugin._plugin_instances:
248
-            if (not isinstance(value, inst)):
249
-                msg = "Following plugin types do not exists in the loader: %s"
250
-                raise SettingsValidationError(msg % value)
251
-    return value
252 241
 
253
-def plugins_val(value):
254
-    spl = value.split('.')
255
-    if len(spl) < 1:
256
-        msg = "Expected a value in the form PLUGIN.NAME or PLUGIN.VERSION but got : %s"
242
+def plugin_val(value):
243
+    if spl = value.split('.')
244
+    if len(spl) != 2:
245
+        msg = "Expected a value in the form PLUGIN.TYPE but got : %s"
257 246
         raise SettingsValidationError(msg % value)
258 247
     value = tuple(spl)
259
-    #Late validation hook
260
-    @LodelHook('lodel2_dyncode_bootstraped')
261
-    def plugin_check(hookname, caller, payload):
262
-        from lodel import plugin
263
-        pluginnames = { cls.__type.lower():cls for cls in dyncode.dynclasses}
264
-        if value[0].lower() not in pluginsnames:
265
-            msg = "Following plugin types do not exists in the loader: %s"
266
-            raise SettingsValidationError(msg % value[0])
267
-        ccls = classnames[value[0].lower()]
268
-        if value[1].lower() not in ccls.fieldnames(True):
269
-            msg = "Following field not found in class %s : %s"
270
-            raise SettingsValidationError(msg % value)
271
-    return value
248
+        #Late validation hook
249
+        @LodelHook('lodel2_dyncode_bootstraped')
250
+        def type_check(hookname, caller, payload):
251
+            from lodel import plugin
252
+            typesname = { cls.__name__.lower():cls for cls in plugin.PLUGINS_TYPE}
253
+            if value[1].lower() not in typesname:
254
+                msg = "Following plugin type do not exist in plugin list %s : %s"
255
+                raise SettingsValidationError(msg % value)
256
+            return value
257
+    plug_type_val = plugin_val(value)
258
+    return plug_type_val
259
+
272 260
 
273 261
 #
274 262
 #   Default validators registration

+ 2
- 2
tests/datahandlers/test_boolean.py View File

@@ -10,12 +10,12 @@ class BooleanTestCase(unittest.TestCase):
10 10
 
11 11
         # correct values
12 12
         for test_value in [True, False]:
13
-            value, error = test_boolean.check_data_value(test_value)
13
+            _, error = test_boolean.check_data_value(test_value)
14 14
             self.assertIsNone(error)
15 15
 
16 16
         # incorrect values
17 17
         for test_value in ['ok', 'True', 'False']:
18
-            value, error = test_boolean.check_data_value(test_value)
18
+            _, error = test_boolean.check_data_value(test_value)
19 19
             self.assertIsNotNone(error)
20 20
 
21 21
     def test_can_override(self):

Loading…
Cancel
Save