commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7865 - trunk/gnue-forms/src/input/displayHandlers


From: jamest
Subject: [gnue] r7865 - trunk/gnue-forms/src/input/displayHandlers
Date: Mon, 15 Aug 2005 20:54:44 -0500 (CDT)

Author: jamest
Date: 2005-08-15 20:54:42 -0500 (Mon, 15 Aug 2005)
New Revision: 7865

Modified:
   trunk/gnue-forms/src/input/displayHandlers/Cursor.py
   trunk/gnue-forms/src/input/displayHandlers/DateTime.py
   trunk/gnue-forms/src/input/displayHandlers/__init__.py
Log:
remove mx DateTime usage from the date handler
more bugfix/cleanup in display handlers


Modified: trunk/gnue-forms/src/input/displayHandlers/Cursor.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Cursor.py        2005-08-14 
02:41:43 UTC (rev 7864)
+++ trunk/gnue-forms/src/input/displayHandlers/Cursor.py        2005-08-16 
01:54:42 UTC (rev 7865)
@@ -226,6 +226,7 @@
     self._selection1 = None
 
     if self.modified:
+      # TODO: buildValue should raise an exception instead of return False
       if self._buildValue():
         if self.field._allowedValues and \
            not self.field._allowedValues.has_key("%s" % self.value):

Modified: trunk/gnue-forms/src/input/displayHandlers/DateTime.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/DateTime.py      2005-08-14 
02:41:43 UTC (rev 7864)
+++ trunk/gnue-forms/src/input/displayHandlers/DateTime.py      2005-08-16 
01:54:42 UTC (rev 7865)
@@ -26,22 +26,10 @@
 """
 __revision__ = "$Id:$"
 
-import sys, time
+import sys, time, datetime
 
 from gnue.forms.input.displayHandlers.Cursor import BaseCursor
 
-try:
-  from mx.DateTime import DateTime, mktime
-except ImportError:
-  print """
-   This GNUe tool requires mxDateTime to be installed
-
-   You can find the mxDateTime at
-
-   http://www.lemburg.com/files/python/mxDateTime.html
-"""
-  sys.exit()
-
 class DateTime(BaseCursor):
   """
   Class to handle the display and entry of date based fields.
@@ -53,10 +41,6 @@
     self.__inputMask = inputMask
 
 
-  def setValue(self, value):
-    return BaseCursor.setValue(self, value)
-
-
   # TODO: Replace with format mask
   def _buildDisplayHelper(self, value, editing):
     if editing:
@@ -80,42 +64,42 @@
 
 
   def _buildValue(self):
-
     if not len(self.work):
       self.value = None
       return True
 
     # TODO: Replace with format mask
     if self.__inputMask:
+      
       try:
-        # mx.DateTime.strptime is not available under windows
-        self.value = mktime (time.strptime (self.work, self.__inputMask))
-      except:
+        tempVal = time.strptime (self.work, self.__inputMask)
+        self.value = datetime.datetime(*tempVal[0:6])
+      except ValueError:
+        gDebug(6,"Date format %s invalid for mask %s" % (self.work, 
self.__inputMask))
         return False
       return True
     
-    try:
-      # TODO: Candidate for maketrans?
-      value = self.work.replace('.','/').replace('-','/')
+    # TODO: Candidate for maketrans?
+    # TODO: This logic does not work for timestamps
+    #       as it skips the hour,minute, second
+    value = self.work.replace('.','/').replace('-','/')
 
-      # Support for quick entry like '123102' for '12/31/02'
-      if len(value) in (6, 8) and value.find('/') == -1:
-        month = value[:2]
-        day = value[2:4]
-        year = value[4:]
+    
+    # Support for quick entry like '123102' for '12/31/02'
+    if len(value) in (6, 8) and value.find('/') == -1:
+      month = value[:2]
+      day = value[2:4]
+      year = value[4:]
+    else:
+      month, day, year = value.split('/')
+
+    # TODO: Shouldn't the 50 be a config option
+    year = int(year)
+    if year < 100:
+      if year > 50:
+        year = year + 1900
       else:
-        month, day, year = value.split('/')
+        year = year + 2000
 
-      # TODO: Shouldn't the 50 be a config option
-      year = int(year)
-      if year < 100:
-        if year > 50:
-          year = year + 1900
-        else:
-          year = year + 2000
-
-      self.value = DateTime(year, int(month), int(day))
-
-      return True
-    except:
-      return False
+    self.value = datetime.datetime(year, int(month), int(day))
+    return True

Modified: trunk/gnue-forms/src/input/displayHandlers/__init__.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/__init__.py      2005-08-14 
02:41:43 UTC (rev 7864)
+++ trunk/gnue-forms/src/input/displayHandlers/__init__.py      2005-08-16 
01:54:42 UTC (rev 7865)
@@ -53,11 +53,17 @@
                        'password':Password,
                        'number':  Numeric,
                       }
-
-  gDebug(6, "Creating display handler for %s style entry" % entry.style)
   
+  if entry._field.typecast == 'number':
+    key = 'number'
+  elif entry._field.typecast == 'date':
+    key = 'date'
+  else:
+    key = entry.style
+    
+  gDebug(6, "Creating display handler for entry key %s" % key)
   try:
-    constructor = classConstructors[entry.style]
+    constructor = classConstructors[key]
   except KeyError:
     constructor = Text
   





reply via email to

[Prev in Thread] Current Thread [Next in Thread]