commit-gnue
[Top][All Lists]
Advanced

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

r6496 - trunk/gnue-appserver/src


From: johannes
Subject: r6496 - trunk/gnue-appserver/src
Date: Thu, 14 Oct 2004 08:49:10 -0500 (CDT)

Author: johannes
Date: 2004-10-14 08:49:09 -0500 (Thu, 14 Oct 2004)
New Revision: 6496

Modified:
   trunk/gnue-appserver/src/labels.py
Log:
Add creation- and modification-stamps at the bottom of every page automatically


Modified: trunk/gnue-appserver/src/labels.py
===================================================================
--- trunk/gnue-appserver/src/labels.py  2004-10-14 10:19:54 UTC (rev 6495)
+++ trunk/gnue-appserver/src/labels.py  2004-10-14 13:49:09 UTC (rev 6496)
@@ -24,12 +24,23 @@
 import string
 import math
 import mx.DateTime
+import copy
 
 from xml.sax import saxutils
 from gnue.appserver.classrep import Namespace
+from gnue.common.apps import errors
 
 
 # =============================================================================
+# Exceptions
+# =============================================================================
+
+class SystemClassError (errors.UserError):
+  def __init__ (self, classname):
+    msg = u_("'%s' is a system class and cannot be edited.") % classname
+    errors.UserError.__init__ (self, msg)
+
+# =============================================================================
 # This class encapsulates the property of a business object class
 # =============================================================================
 
@@ -63,6 +74,7 @@
     self.typecast    = None
     self.inputMask   = None
     self.displayMask = None
+    self.buddy       = None
     self.triggers    = {}
 
     masks  = ['%x', '%X', '%x %X']
@@ -94,8 +106,10 @@
     """
     This function updates the instance with all label information
     """
+
     self.label  = label.label
-    self.page   = label.page
+    if label.page is not None:
+      self.page = label.page
     self.pos    = label.position
     self.search = label.search
     self.info   = label.info
@@ -182,13 +196,20 @@
     startX    = 1 + self.labelWidth + 1
     self.left = startX
     maxWidth -= startX + 1
-    if self.ref is None:
+    if self.ref is None and self.buddy is None:
       if self.type == 'string' and self.length is None:
         self.width = maxWidth
       else:
         self.width = min (maxWidth, self.fieldLength)
 
       self.widgetSpace = self.width
+
+    elif self.buddy is not None:
+      self.width       = self.fieldLength
+      self.buddy.left  = startX + self.width + 1
+      self.buddy.width = self.buddy.left + self.buddy.fieldLength
+      self.widgetSpace = self.width + self.buddy.width + 1
+
     else:
       refLength = 0
       refStart  = startX
@@ -234,6 +255,11 @@
   _START_ROW  = 1       # starting row for widgets
   _MIN_HEIGHT = 2       # default minimum height of stretchable widgets
 
+  _SPECIALS = {'gnue_createdate': {'Label': u_("Created"),
+                                   'Buddy': 'gnue_createuser'},
+               'gnue_modifydate': {'Label': u_("Last modified"),
+                                   'Buddy': 'gnue_modifyuser'}}
+
   # ---------------------------------------------------------------------------
   # Constructor
   # ---------------------------------------------------------------------------
@@ -258,12 +284,16 @@
       self.languages.append (language.split ('_') [0])
     self.languages.append (language)
 
-    self.properties = self.__getPropertyDict (self.fullName)
+    (self.properties, self.specials) = self.__getPropertyDict (self.fullName)
 
+    if not len (self.properties.keys ()):
+      raise SystemClassError, self.fullName
+
     self.__loadLabels (self.fullName, self.properties)
     self.__fillupReferences ()
     self.__updateEntryStyle ()
     self.__updateSources ()
+    self.__updateSpecials ()
     self.pages = self.__buildVirtualPages ()
     self.visPages = self.__buildVisualPages ()
     self.__arangePages ()
@@ -276,13 +306,18 @@
 
   def __getPropertyDict (self, classname):
     """
-    This function retrieves all properties and of the requested class,
+    This function retrieves all properties of the requested class,
     including calculated fields.
+
     @param classname: fully qualified name of the requested class
-    @return: dictionary of all properties and calculated fields, where the
-        fieldnames act as key and the values are Property instances.
+
+    @return: tuple of two dictionaries. The first dictionary holds all
+        properties and calculated fields and the second dictionary holds all
+        special properties. In both dictionaries the keys are fieldnames and
+        the values are Property instances
     """
-    result = {}
+    result   = {}
+    specials = {}
 
     (module, klass) = Namespace.splitName (classname)
 
@@ -292,7 +327,12 @@
 
     pList = ['gnue_name', 'gnue_length', 'gnue_type', 'gnue_scale']
     for prop in find ('gnue_property', cond, [], pList):
-      if prop.gnue_type == 'id':
+      if prop.gnue_module.gnue_name == 'gnue' or prop.gnue_type == 'id':
+        if prop.gnue_name in ['createdate', 'modifydate', 'createuser',
+                              'modifyuser']:
+          record = Property (prop)
+          specials [record.fullName] = record
+
         continue
 
       record = Property (prop)
@@ -314,7 +354,7 @@
       record = Property (proc, True)
       result [record.fullName] = record
 
-    return result
+    return (result, specials)
 
 
   # ---------------------------------------------------------------------------
@@ -386,7 +426,7 @@
     """
     for item in self.properties.values ():
       if '_' in item.type:
-        result = self.__getPropertyDict (item.type)
+        (result, dummy) = self.__getPropertyDict (item.type)
         self.__loadLabels (item.type, result, True)
 
         if len (result.keys ()):
@@ -419,12 +459,14 @@
     search-dialogs the first field get's an entry all others are labels.
     After this function is finished all properties have a valid member 'style'
     """
+
     for prop in self.properties.values ():
       prop.style = None
 
       if prop.ref is None:
         if prop.type == 'boolean':
           prop.style = 'checkbox'
+
       else:
         if prop.isLookup ():
           for refItem in prop.refOrder:
@@ -438,7 +480,11 @@
           for refItem in prop.refOrder [1:]:
             refItem.style = 'label'
 
+    # all special items (like stamps) will become labels
+    for item in self.specials.values ():
+      item.style = 'label'
 
+
   # ---------------------------------------------------------------------------
   # Update the sources- and blocks-dictionary and their field sequences
   # ---------------------------------------------------------------------------
@@ -449,7 +495,7 @@
     """
     self.__addToSources ('dtsMaster', self.fullName)
 
-    for prop in self.properties.values ():
+    for prop in self.properties.values () + self.specials.values ():
       if prop.ref is None:
         dtsName    = "dtsMaster"
         blkName    = "blkMaster"
@@ -493,6 +539,27 @@
 
 
   # ---------------------------------------------------------------------------
+  # Update the list of special properties
+  # ---------------------------------------------------------------------------
+
+  def __updateSpecials (self):
+    """
+    This function iterates over the available special properties and join them
+    according to the buddy-parts given in the _SPECIALS dictionary.
+    """
+
+    for (name, item) in self.specials.items ():
+      if self._SPECIALS.has_key (name):
+        spec  = self._SPECIALS [name]
+        buddy = spec ['Buddy']
+
+        item.label = spec ['Label']
+        if self.specials.has_key (buddy):
+          item.buddy = self.specials [buddy]
+          del self.specials [buddy]
+
+
+  # ---------------------------------------------------------------------------
   # Add a property to the given block dictionary
   # ---------------------------------------------------------------------------
 
@@ -557,6 +624,7 @@
     all items get a property 'minHeight' set, which determines the minimum
     height needed by a field. If minHeight is None, a field can be stretched
     vertically to consume the available space left.
+
     @return: dictionary with all virtual pages, where the page-names act as
         keys and the values are sequences with the properties per page. The
         property sequences are already ordered.
@@ -565,9 +633,6 @@
 
     # add fields to their virtual pages
     for item in self.properties.values ():
-      if not result.has_key (item.page):
-        result [item.page] = []
-
       item.addHeight = 0
       # specify a minimum height required for a field
       if item.type == 'string' and item.length is None:
@@ -575,9 +640,19 @@
       else:
         item.minHeight = 1
 
+      if not result.has_key (item.page):
+        result [item.page] = []
 
       result [item.page].append (item)
 
+    # add special properties to *all* pages
+    for item in self.specials.values ():
+      item.addHeight = 0
+      item.minHeight = 1
+
+    for plist in result.values ():
+      plist.extend ([copy.deepcopy (p) for p in self.specials.values ()])
+
     # now order all fields per virtual page
     for page in result.keys ():
       pOrder = []
@@ -661,6 +736,10 @@
           row = self._START_ROW
 
         item.row    = row
+        if item.buddy is not None:
+          item.buddy.row    = item.row
+          item.buddy.height = item.height
+
         cPage.append (item)
 
         row += item.height
@@ -740,7 +819,9 @@
     self.code.extend (self._getXMLTag ('layout', attrs, indent, True))
 
     focusOrder = 1
-    for page in self.visPages.keys ():
+    pageList = self.visPages.keys ()
+    pageList.sort ()
+    for page in pageList:
       ind = indent + "  "
       attrs = {'name': page}
       self.code.extend (self._getXMLTag ('page', attrs, ind, True))
@@ -757,29 +838,13 @@
 
       for item in self.visPages [page]:
         if item.ref is None:
-          attrs = {'c:x'     : item.left,
-                   'c:y'     : item.row,
-                   'c:width' : item.width,
-                   'c:height': item.height,
-                   'block'   : item.block,
-                   'field'   : item.fieldName}
-
-          if focusOrder == 1:
-            attrs ['focusorder'] = 1
-
+          self.__addField (item, focusOrder, find)
           focusOrder += 1
 
-          if item.displayMask is not None:
-            attrs ['displaymask'] = item.displayMask
+          if item.buddy is not None:
+            self.__addField (item.buddy, focusOrder, find)
+            focusOrder += 1
 
-          if item.inputMask is not None:
-            attrs ['inputmask'] = item.inputMask
-
-          if item.style is not None:
-            attrs ['style'] = item.style
-
-          self.code.extend (self._getXMLTag ('entry', attrs, find))
-
         else:
           for refItem in item.refOrder:
             if refItem.width is None:
@@ -809,7 +874,33 @@
     return string.join (self.code, "\n")
 
 
+  # ---------------------------------------------------------------------------
+  # add an entry to the page
+  # ---------------------------------------------------------------------------
 
+  def __addField (self, item, focusOrder, find):
+    attrs = {'c:x'     : item.left,
+             'c:y'     : item.row,
+             'c:width' : item.width,
+             'c:height': item.height,
+             'block'   : item.block,
+             'field'   : item.fieldName}
+
+    if focusOrder == 1:
+      attrs ['focusorder'] = 1
+
+    if item.displayMask is not None:
+      attrs ['displaymask'] = item.displayMask
+
+    if item.inputMask is not None:
+      attrs ['inputmask'] = item.inputMask
+
+    if item.style is not None:
+      attrs ['style'] = item.style
+
+    self.code.extend (self._getXMLTag ('entry', attrs, find))
+
+
   # ---------------------------------------------------------------------------
   # Add blocks to the form code
   # ---------------------------------------------------------------------------





reply via email to

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