Actions

icon Post
text/html Subscribe
text/html Unsubscribe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [qmtest] Is there a reason why BooleanField does not return boolean objects?


  • To: Stefan Seefeld <stefan@xxxxxxxxxxxxxxxx>
  • Subject: Re: [qmtest] Is there a reason why BooleanField does not return boolean objects?
  • From: Mohamed Barwani <mohamedb@xxxxxxx>
  • Date: Thu, 24 Apr 2008 10:36:47 +1000

Stefan Seefeld wrote:

That's a good question. I believe this is because QMTest used to be
much more GUI-centric than it is today, and there isn't a very robust
 separation between 'Model' and 'View' in QMTest.


Would the following patch be any use to anyone.. Certainly makes my life
easier :)


---
 qm/fields.py |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/qm/fields.py b/qm/fields.py
index 6434680..db1c2fe 100644
--- a/qm/fields.py
+++ b/qm/fields.py
@@ -1804,12 +1804,30 @@ class BooleanField(EnumerationField):

     def Validate(self, value):

-        if qm.common.parse_boolean(value):
-            value = "true"
-        else:
-            value = "false"
+        qm.common.parse_boolean(value)
         return super(BooleanField, self).Validate(value)
+
+    def GetValueFromDomNode(self, node, attachment_store):
+
+        value = super(BooleanField, self).GetValueFromDomNode(
+                                              node, attachment_store)
+
+        return bool(qm.common.parse_boolean(value))
+
+    def ParseTextValue(self, value):
+
+        # make sure its valid and convert too boolean
+        return bool(qm.common.parse_boolean(value))
+
+    def FormatValueAsHtml(self, server, value, style, name = None):

+       if value:
+           value = "true"
+       else:
+           value = "false"
+
+        return super(BooleanField, self).FormatValueAsHtml(
+                                             server, value ,style, name)

 ########################################################################


--
Mohamed Barwani
ASGQA
"The greatest challenge to any thinker is stating the problem in a way
that will allow a solution."
    - Bertrand Russell