commit-gnue
[Top][All Lists]
Advanced

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

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


From: johannes
Subject: [gnue] r9322 - trunk/gnue-forms/src/input/displayHandlers
Date: Wed, 17 Jan 2007 09:36:57 -0600 (CST)

Author: johannes
Date: 2007-01-17 09:36:56 -0600 (Wed, 17 Jan 2007)
New Revision: 9322

Added:
   trunk/gnue-forms/src/input/displayHandlers/datehandler.py
Removed:
   trunk/gnue-forms/src/input/displayHandlers/DateTime.py
Modified:
   trunk/gnue-forms/src/input/displayHandlers/__init__.py
Log:
Renamed display handler for date related entries so it does not conflict 
on VFAT anymore


Deleted: trunk/gnue-forms/src/input/displayHandlers/DateTime.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/DateTime.py      2007-01-17 
13:57:54 UTC (rev 9321)
+++ trunk/gnue-forms/src/input/displayHandlers/DateTime.py      2007-01-17 
15:36:56 UTC (rev 9322)
@@ -1,117 +0,0 @@
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2002-2007 Free Software Foundation
-#
-# FILE:
-# GFDisplayHandler.py
-#
-# $Id$
-"""
-DisplayHandler classes for Forms input validation
-"""
-__revision__ = "$Id:$"
-
-import sys, time, datetime
-
-from gnue.common.apps import errors
-from gnue.forms.input.displayHandlers.Cursor import BaseCursor
-
-# =============================================================================
-# Exceptions
-# =============================================================================
-
-class InvalidDateLiteral (errors.UserError):
-  def __init__ (self, value):
-    msg = u_("'%(value)s' is not a valid date-literal") % {'value': value}
-    errors.UserError.__init__ (self, msg)
-
-
-# =============================================================================
-# Display handler for Date and Time values
-# =============================================================================
-
-class DateTime(BaseCursor):
-  """
-  Class to handle the display and entry of date based fields.
-  """
-  def __init__(self, entry, eventHandler, subEventHandler, displayMask,
-               inputMask):
-    BaseCursor.__init__(self, entry, eventHandler, subEventHandler,
-            displayMask, inputMask)
-    self.__displayMask = displayMask
-    self.__inputMask = inputMask
-
-
-  def build_display(self, value, editing):
-    if editing:
-      if self.__inputMask:
-        format = self.__inputMask
-      else:
-        format = "%m/%d/%Y"
-    else:
-      if self.__displayMask:
-        format = self.__displayMask
-      else:
-        format = "%m/%d/%y"
-
-    if value in (None, ""):
-      return ""
-    try:
-      return value.strftime (str (format))
-    except AttributeError:
-      return str(value)
-
-
-  def parse_display(self, display):
-    if not len(display):
-        return None
-
-    # TODO: Replace with format mask
-    if self.__inputMask:
-      try:
-        tempVal = time.strptime (display, self.__inputMask)
-        return datetime.datetime(*tempVal[0:6])
-      except ValueError:
-        raise InvalidDateLiteral, display
-    
-    # TODO: Candidate for maketrans?
-    # TODO: This logic does not work for timestamps
-    #       as it skips the hour,minute, second
-    value = display.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:]
-
-    elif value.find ('/') == -1:
-      raise InvalidDateLiteral, value
-
-    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:
-        year = year + 2000
-
-    return datetime.datetime(year, int(month), int(day))

Modified: trunk/gnue-forms/src/input/displayHandlers/__init__.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/__init__.py      2007-01-17 
13:57:54 UTC (rev 9321)
+++ trunk/gnue-forms/src/input/displayHandlers/__init__.py      2007-01-17 
15:36:56 UTC (rev 9322)
@@ -27,7 +27,9 @@
 __all__ = [
       "Checkbox",
       "Component",
-      "DateTime",
+      ("datehandler", "Date"),
+      ("datehandler", "Time"),
+      ("datehandler", "DateTime"),
       "Dropdown",
       "Listbox",
       "Numeric",
@@ -35,8 +37,13 @@
       "Text",
        ]
 
-for module in __all__:
-  exec "from gnue.forms.input.displayHandlers.%s import %s" % (module, module)
+for item in __all__:
+    if isinstance(item, tuple):
+        (module, classname) = item
+    else:
+        module = classname = item
+    exec "from gnue.forms.input.displayHandlers.%s import %s" % (module,
+          classname)
 
 def factory(entry, eventHandler, subEventHandler, displayMask, inputMask):
   """
@@ -46,12 +53,14 @@
         type passed in.
   """
   classConstructors = {'checkbox':Checkbox,
-                       'date':    DateTime,
+                       'date':    Date,
+                       'time': Time,
+                       'datetime': DateTime,
                        'dropdown': Dropdown,
                        'listbox': Listbox,
                        'password':Password,
                        'number':  Numeric,
-                      'image': None,
+                       'image': None,
                       }
   
   if entry._type == 'GFImage':
@@ -67,7 +76,7 @@
   elif entry._field.datatype == 'number':
     key = 'number'
   elif entry._field.datatype in ['date', 'time', 'datetime']:
-    key = 'date'
+    key = entry._field.datatype
   elif entry._field.datatype == 'boolean':
     key = 'checkbox'
   else:

Copied: trunk/gnue-forms/src/input/displayHandlers/datehandler.py (from rev 
9311, trunk/gnue-forms/src/input/displayHandlers/DateTime.py)
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/DateTime.py      2007-01-15 
07:24:57 UTC (rev 9311)
+++ trunk/gnue-forms/src/input/displayHandlers/datehandler.py   2007-01-17 
15:36:56 UTC (rev 9322)
@@ -0,0 +1,123 @@
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2002-2007 Free Software Foundation
+#
+# FILE:
+# GFDisplayHandler.py
+#
+# $Id$
+"""
+DisplayHandler classes for Forms input validation
+"""
+__revision__ = "$Id:$"
+
+import sys, time, datetime
+
+from gnue.common.apps import errors
+from gnue.forms.input.displayHandlers.Cursor import BaseCursor
+
+# =============================================================================
+# Exceptions
+# =============================================================================
+
+class InvalidDateLiteral (errors.UserError):
+  def __init__ (self, value):
+    msg = u_("'%(value)s' is not a valid date-literal") % {'value': value}
+    errors.UserError.__init__ (self, msg)
+
+
+# =============================================================================
+# Display handler for Date and Time values
+# =============================================================================
+
+class Date(BaseCursor):
+    pass
+
+class Time(BaseCursor):
+    pass
+
+class DateTime(BaseCursor):
+  """
+  Class to handle the display and entry of date based fields.
+  """
+  def __init__(self, entry, eventHandler, subEventHandler, displayMask,
+               inputMask):
+    BaseCursor.__init__(self, entry, eventHandler, subEventHandler,
+            displayMask, inputMask)
+    self.__displayMask = displayMask
+    self.__inputMask = inputMask
+
+
+  def build_display(self, value, editing):
+    if editing:
+      if self.__inputMask:
+        format = self.__inputMask
+      else:
+        format = "%m/%d/%Y"
+    else:
+      if self.__displayMask:
+        format = self.__displayMask
+      else:
+        format = "%m/%d/%y"
+
+    if value in (None, ""):
+      return ""
+    try:
+      return value.strftime (str (format))
+    except AttributeError:
+      return str(value)
+
+
+  def parse_display(self, display):
+    if not len(display):
+        return None
+
+    # TODO: Replace with format mask
+    if self.__inputMask:
+      try:
+        tempVal = time.strptime (display, self.__inputMask)
+        return datetime.datetime(*tempVal[0:6])
+      except ValueError:
+        raise InvalidDateLiteral, display
+    
+    # TODO: Candidate for maketrans?
+    # TODO: This logic does not work for timestamps
+    #       as it skips the hour,minute, second
+    value = display.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:]
+
+    elif value.find ('/') == -1:
+      raise InvalidDateLiteral, value
+
+    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:
+        year = year + 2000
+
+    return datetime.datetime(year, int(month), int(day))





reply via email to

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