Hi,

as result of discussion on Param and environment/context, here is patch
to fix
    https://fedorahosted.org/freeipa/ticket/1549
    https://fedorahosted.org/freeipa/ticket/1550

CLI and Web UI work.
-- 
/ Alexander Bokovoy
From 7bbec097dfac402a4b79edc8685b736a53d06aed Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <aboko...@redhat.com>
Date: Mon, 1 Aug 2011 17:28:04 +0300
Subject: [PATCH] Use cli_name if possible to return errors via exceptions

https://fedorahosted.org/freeipa/ticket/1549
https://fedorahosted.org/freeipa/ticket/1550
---
 ipalib/parameters.py |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 
e1c0b093a94fb99a34e0928f79e56f0c9f86a0c0..e26c33ec96e645b3c7579de15b26dbbbb3ccff86
 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -725,10 +725,10 @@ class Param(ReadOnly):
         """
         if value is None:
             if self.required:
-                if context == 'cli':
-                    raise RequirementError(name=self.cli_name)
-                else:
-                    raise RequirementError(name=self.name)
+                    name = self.cli_name
+                    if not name:
+                        name = self.name
+                    raise RequirementError(name=name)
             return
         if self.multivalue:
             if type(value) is not tuple:
@@ -744,7 +744,10 @@ class Param(ReadOnly):
 
     def _validate_scalar(self, value, index=None):
         if type(value) is not self.type:
-            raise ValidationError(name=self.name,
+            name = self.cli_name
+            if not name:
+                name = self.name
+            raise ValidationError(name=name,
                 error='need a %r; got %r (a %r)' % (
                     self.type, value, type(value)
                 )
@@ -1672,10 +1675,16 @@ class AccessTime(Str):
         try:
             self._check(value)
         except ValueError, e:
-            raise ValidationError(name=self.cli_name, error=e.args[0])
+            name = self.cli_name
+            if not name:
+                name = self.name
+            raise ValidationError(name=name, error=e.args[0])
         except IndexError:
+            name = self.cli_name
+            if not name:
+                name = self.name
             raise ValidationError(
-                name=self.cli_name, error='incomplete time value'
+                name=name, error='incomplete time value'
             )
         return None
 
-- 
1.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to