commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8489 - trunk/gnue-forms/src/GFObjects


From: johannes
Subject: [gnue] r8489 - trunk/gnue-forms/src/GFObjects
Date: Thu, 8 Jun 2006 07:28:55 -0500 (CDT)

Author: johannes
Date: 2006-06-08 07:28:54 -0500 (Thu, 08 Jun 2006)
New Revision: 8489

Modified:
   trunk/gnue-forms/src/GFObjects/GFEntry.py
   trunk/gnue-forms/src/GFObjects/GFField.py
   trunk/gnue-forms/src/GFObjects/GFObj.py
   trunk/gnue-forms/src/GFObjects/GFTabStop.py
Log:
Code cleanup and basic validation stub


Modified: trunk/gnue-forms/src/GFObjects/GFEntry.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFEntry.py   2006-05-30 05:09:42 UTC (rev 
8488)
+++ trunk/gnue-forms/src/GFObjects/GFEntry.py   2006-06-08 12:28:54 UTC (rev 
8489)
@@ -122,7 +122,13 @@
 
         return self.navigable and self._block.navigable and not self.hidden
 
+    # -------------------------------------------------------------------------
 
+    def _validate_(self):
+
+        self._field.validate()
+
+
     # =========================================================================
     # Trigger functions
     # =========================================================================

Modified: trunk/gnue-forms/src/GFObjects/GFField.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFField.py   2006-05-30 05:09:42 UTC (rev 
8488)
+++ trunk/gnue-forms/src/GFObjects/GFField.py   2006-06-08 12:28:54 UTC (rev 
8489)
@@ -45,7 +45,14 @@
         msg = u_("Datasource '%(name)s' not found") % {'name': name}
         GParser.MarkupError.__init__ (self, msg, field._url, field._lineNumber)
 
+# =============================================================================
 
+class MinimumLengthError(errors.UserError):
+    def __init__(self, name, min_length):
+        msg = u_("Minimum required length for field '%(name)s': %(len)d") \
+                % {'name': name, 'len': min_length}
+        errors.UserError.__init__(self, msg)
+
 # =============================================================================
 # A field of a block
 # =============================================================================
@@ -270,6 +277,26 @@
 
 
     # -------------------------------------------------------------------------
+    # Validate
+    # -------------------------------------------------------------------------
+
+    def validate(self):
+        """
+        Validate the current value of the field
+
+        @raises MinimumLengthError: if a minimum field length is specified and
+          the current value is too short (but not None)
+        """
+        
+        value = self.getValue()
+        vstr  = "%s" % value
+
+        if self.minLength and value is not None:
+            if len(vstr) and len(vstr) < self.minLength:
+                raise MinimumLengthError(self.name, self.minLength)
+
+
+    # -------------------------------------------------------------------------
     # Implementation of virtual methods
     # -------------------------------------------------------------------------
 

Modified: trunk/gnue-forms/src/GFObjects/GFObj.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFObj.py     2006-05-30 05:09:42 UTC (rev 
8488)
+++ trunk/gnue-forms/src/GFObjects/GFObj.py     2006-06-08 12:28:54 UTC (rev 
8489)
@@ -28,26 +28,31 @@
 from gnue.common.logic.GTrigger import GTriggerExtension
 from gnue.common.definitions import GParser
 
+__all__ = ['BlockNotFoundError', 'FieldNotFoundError', 'GFObj']
 
 # =============================================================================
 # Exceptions
 # =============================================================================
 
 class BlockNotFoundError(GParser.MarkupError):
-  def __init__(self, item):
-    itemType = item._type[2:]
-    msg = u_("%(item)s '%(name)s' references non-existent block '%(block)s'") \
-          % {'item': itemType, 'name': item.name, 'block': item.block}
-    GParser.MarkupError.__init__(self, msg, item._url, item._lineNumber)
+    """ Element references non-existent block """
+    def __init__(self, item):
+        itemType = item._type[2:]
+        msg = u_("%(item)s '%(name)s' references non-existent "
+                 "block '%(block)s'") \
+              % {'item': itemType, 'name': item.name, 'block': item.block}
+        GParser.MarkupError.__init__(self, msg, item._url, item._lineNumber)
 
 # =============================================================================
 
 class FieldNotFoundError(GParser.MarkupError):
-  def __init__(self, item):
-    itemType = item._type[2:]
-    msg = u_("%(item)s '%(name)s' references non-existent field '%(field)s'") \
-          % {'item': itemType, 'name': item.name, 'field': item.field}
-    GParser.MarkupError.__init__(self, msg, item._url, item._lineNumber)
+    """ Element refernces non-existent field """
+    def __init__(self, item):
+        itemType = item._type[2:]
+        msg = u_("%(item)s '%(name)s' references non-existent "
+                 "field '%(field)s'") \
+              % {'item': itemType, 'name': item.name, 'field': item.field}
+        GParser.MarkupError.__init__(self, msg, item._url, item._lineNumber)
 
 
 # =============================================================================
@@ -65,10 +70,10 @@
     # Constructor
     # -------------------------------------------------------------------------
 
-    def __init__(self, parent=None, type='GFObj'):
+    def __init__(self, parent=None, object_type='GFObj'):
     
         GTriggerExtension.__init__(self)
-        GObj.__init__(self, parent, type)
+        GObj.__init__(self, parent, object_type)
 
         self.hidden = False
         self.readonly = False
@@ -78,6 +83,7 @@
         self._rows = 1
         self._gap = 0
         self._inits = [self.phase_1_init]
+        self._form = None
 
         # The reference to the uiWidget will be set by the
         # uidrivers._base.UIdriver._buildUI () function.
@@ -88,7 +94,7 @@
     # Check wether an object is navigable or not
     # -------------------------------------------------------------------------
 
-    def is_navigable(self, mode = 'edit'):
+    def is_navigable(self, mode='edit'):
         """
         Return wether the object is currently navigable or not.
 
@@ -140,14 +146,14 @@
     # Recalculate the visible index of an object
     # -------------------------------------------------------------------------
 
-    def recalculate_visible(self, adjustment, currentRecord, recordCount):
+    def recalculate_visible(self, adjustment, cur_record, rec_count):
         """
         Recalculate the visible index of an object. This determines that real 
UI
         widget of a 'row-based grid' which should be visible.
 
         @param adjustment: value to change the visible index, e.g. 1 or -1
-        @param currentRecord: the currently active record
-        @param recordCount: the number of records available at all
+        @param cur_record: the currently active record
+        @param rec_count: the number of records available at all
 
         As a result of this recalculation the property self._visibleIndex will
         be set to the new value.
@@ -158,13 +164,13 @@
                         int(self._rows)-1)
 
             # Don't let the index pass the number of records
-            lowestVisible = max(currentRecord - index, 0)
-            if lowestVisible + index > recordCount:
+            lowestVisible = max(cur_record - index, 0)
+            if lowestVisible + index > rec_count:
                 index = index -1
 
             # If the current record has rolled around from the top to the
             # bottom then reset the counter.
-            if currentRecord == 0:
+            if cur_record == 0:
                 index = 0
 
             self._visibleIndex = index

Modified: trunk/gnue-forms/src/GFObjects/GFTabStop.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-05-30 05:09:42 UTC (rev 
8488)
+++ trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-06-08 12:28:54 UTC (rev 
8489)
@@ -28,6 +28,8 @@
 from gnue.common import events
 from gnue.forms.GFObjects.GFObj import GFObj
 
+__all__ = ['GFTabStop']
+
 # =============================================================================
 # Base class for navigable controls
 # =============================================================================
@@ -39,23 +41,48 @@
     @cvar _navigableInQuery_: If True the object can recieve the keyboard focus
       in query mode, otherwise not
     """
+
+    # -------------------------------------------------------------------------
+    # Attributes
+    # -------------------------------------------------------------------------
   
+    navigable = None
+
+    # -------------------------------------------------------------------------
+    # Class variables
+    # -------------------------------------------------------------------------
+
     _navigableInQuery_ = True
 
+
     # -------------------------------------------------------------------------
     # Constructor
     # -------------------------------------------------------------------------
 
-    def __init__(self, parent, type):
+    def __init__(self, parent, object_type):
 
-        GFObj.__init__(self, parent, type)
+        GFObj.__init__(self, parent, object_type)
 
         # The sub-event handler handles the events that are passed from the
         # GFInstance. This is the event handler that display handlers 
         self.subEventHandler = events.EventController()
 
+        self._page     = None
 
+
     # -------------------------------------------------------------------------
+    # Validate the object
+    # -------------------------------------------------------------------------
+
+    def validate(self):
+        """
+        Validates the object and/or its contents.
+        """
+
+        self._validate_()
+
+
+    # -------------------------------------------------------------------------
     # Implementation of virtual methods
     # -------------------------------------------------------------------------
 
@@ -89,3 +116,13 @@
                 return self.navigable and self._navigableInQuery_
             else:
                 return self.navigable and (not self.readonly)
+
+    # -------------------------------------------------------------------------
+
+    def _validate_(self):
+        """
+        Descendants can overwrite this method to perform a validation. If
+        validation fails, an exception must be raised.
+        """
+
+        pass





reply via email to

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