[node-patches] Change in ovirt-node[master]: plugin: Pull validation into plugin (from TUI)

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Dec 11 20:09:37 UTC 2012


Fabian Deutsch has uploaded a new change for review.

Change subject: plugin: Pull validation into plugin (from TUI)
......................................................................

plugin: Pull validation into plugin (from TUI)

Change-Id: Ic5412f7245348e9d741028e2660dfee18c46f721
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/plugins/__init__.py
M scripts/tui/src/ovirt/node/ui/__init__.py
M scripts/tui/src/ovirt/node/ui/builder.py
3 files changed, 14 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/18/9918/1

diff --git a/scripts/tui/src/ovirt/node/plugins/__init__.py b/scripts/tui/src/ovirt/node/plugins/__init__.py
index f3b2337..2db455c 100644
--- a/scripts/tui/src/ovirt/node/plugins/__init__.py
+++ b/scripts/tui/src/ovirt/node/plugins/__init__.py
@@ -67,6 +67,8 @@
     Errors are propagated back by using Errors/Exceptions.
     """
 
+    validate_changes = True
+
     def __init__(self, application):
         self.__changes = {}
         self.application = application
@@ -120,9 +122,14 @@
         """
         for path, value in changes.items():
             if path in self.validators():
-                msg = self.validators()[path](value)
+                msg = None
+                try:
+                    msg = self.validators()[path](value)
+                except ovirt.node.exceptions.InvalidData as e:
+                    msg = e.message
                 # True and None are allowed values
                 if msg not in [True, None]:
+#                    field = dict(self.ui_content().children)[path].name
                     raise ovirt.node.exceptions.InvalidData(msg)
         return True
 
@@ -214,6 +221,8 @@
             LOGGER.warning("Change is not a dict: %s" % change)
 
         LOGGER.debug("Passing UI change to callback on_change: %s" % change)
+        if self.validate_changes:
+            self.validate(change)
         self.on_change(change)
         self.__changes.update(change)
         LOGGER.debug("Sum of all UI changes up to now: %s" % self.__changes)
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index 84fa56e..ac61af3 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -97,7 +97,8 @@
     """An abstract UI Element pfor user input
     """
 
-    def __init__(self, is_enabled):
+    def __init__(self, name, is_enabled):
+        self.name = name
         self.enabled(is_enabled)
         super(InputElement, self).__init__()
 
@@ -199,7 +200,7 @@
     def __init__(self, label, enabled=True, align_vertical=False):
         self.label = label
         self.align_vertical = align_vertical
-        super(Entry, self).__init__(enabled)
+        super(Entry, self).__init__(label, enabled)
 
 
 class PasswordEntry(Entry):
@@ -208,7 +209,7 @@
 
 class Button(InputElement):
     def __init__(self, label, enabled=True):
-        super(Button, self).__init__(enabled)
+        super(Button, self).__init__(label, enabled)
         self.text(label)
 
     @Element.signal_change
diff --git a/scripts/tui/src/ovirt/node/ui/builder.py b/scripts/tui/src/ovirt/node/ui/builder.py
index 19d556e..9519972 100644
--- a/scripts/tui/src/ovirt/node/ui/builder.py
+++ b/scripts/tui/src/ovirt/node/ui/builder.py
@@ -140,7 +140,6 @@
 
         try:
             change = {path: new_value}
-            plugin.validate(change)
             plugin._on_ui_change(change)
             widget.notice = ""
             widget.valid(True)


--
To view, visit http://gerrit.ovirt.org/9918
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5412f7245348e9d741028e2660dfee18c46f721
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list