commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r6921 - trunk/gnue-common/src/datasources


From: johannes
Subject: [gnue] r6921 - trunk/gnue-common/src/datasources
Date: Tue, 25 Jan 2005 04:14:58 -0600 (CST)

Author: johannes
Date: 2005-01-25 04:14:57 -0600 (Tue, 25 Jan 2005)
New Revision: 6921

Modified:
   trunk/gnue-common/src/datasources/GConditions.py
Log:
Added GCexist condition


Modified: trunk/gnue-common/src/datasources/GConditions.py
===================================================================
--- trunk/gnue-common/src/datasources/GConditions.py    2005-01-24 23:23:45 UTC 
(rev 6920)
+++ trunk/gnue-common/src/datasources/GConditions.py    2005-01-25 10:14:57 UTC 
(rev 6921)
@@ -180,6 +180,7 @@
       item = prefixList [0]
 
       # be nice if there's a condition part missing
+      offset = 1
       if isinstance (item, types.ListType):
         self.buildFromList (item)
         element = self
@@ -190,7 +191,14 @@
 
         element = getattr (sys.modules [__name__], "GC%s" % item) (self)
 
-      for subitem in prefixList [1:]:
+        if item == 'exist':
+          (table, masterlink, detaillink) = prefixList [1:4]
+          element.table      = table
+          element.masterlink = masterlink
+          element.detaillink = detaillink
+          offset = 4
+
+      for subitem in prefixList [offset:]:
         element.buildFromList (subitem)
 
 
@@ -809,6 +817,46 @@
     self._needChildren (self._maxChildren)
     return string.lower (self._children [0].evaluate (lookup))
 
+
+# -----------------------------------------------------------------------------
+# exist
+# -----------------------------------------------------------------------------
+
+class GCexist (GConditionElement):
+  def __init__ (self, parent = None):
+    GConditionElement.__init__ (self, parent, 'GCexist')
+    self.callback = None
+
+  # ---------------------------------------------------------------------------
+  # Evaluate an exist-condition
+  # ---------------------------------------------------------------------------
+
+  def evaluate (self, lookup):
+
+    if self.callback is None:
+      raise NotImplementedError
+
+    return self.callback (self, lookup)
+
+
+  # ---------------------------------------------------------------------------
+  # Convert an element into prefix notation
+  # ---------------------------------------------------------------------------
+
+  def prefixNotation (self):
+    """
+    This function returns the prefix notation of an exist element and all it's
+    children.
+    """
+    result = ['exist', self.table, self.masterlink, self.detaillink]
+    
+    for child in self._children:
+      result.append (child.prefixNotation ())
+
+    return result
+
+
+
 # =============================================================================
 # Return a dictionary of all XML elements available
 # =============================================================================
@@ -822,7 +870,7 @@
          },
       'condition':       {
          'BaseClass': GCondition,
-         'ParentTags':  ('conditions','and','or','not','negate') },
+         'ParentTags':  ('conditions','and','or','not','negate','exist') },
       'cfield':       {
          'BaseClass': GCField,
          'Attributes': {
@@ -923,7 +971,20 @@
          'BaseClass': GClower,
          'ParentTags':  ('eq','ne','lt','le','gt','ge',
                          'like','notlike','between','notbetween') },
-
+      'exist': {
+         'BaseClass': GCexist,
+         'Attributes': {
+            'table': {
+               'Required': True,
+               'Typecast': GTypecast.name },
+            'masterlink': {
+               'Required': True,
+               'Typecast': GTypecast.text},
+            'detaillink': {
+               'Required': True,
+               'Typecast': GTypecast.text}},
+         'ParentTags':  ('eq','ne','lt','le','gt','ge',
+                         'like','notlike','between','notbetween') },
       }
 
   for alteration in updates.keys():
@@ -1538,5 +1599,14 @@
   cond2 = buildTreeFromList (prefix)
   _check_combineConditions (cond1, cond2)
 
+  print "start off"
+  prefix = ['exist', 'customer', 'gnue_id', 'invoice.customer',
+             ['or', ['null'], ['field', 'nfoo']]]
+  cond = buildTreeFromList (prefix)
+  for i in cond.findChildrenOfType ('GCexist', True, True):
+    print i.table, i.masterlink, i.detaillink
+    print "Children:"
+    for c in i._children:
+      print "C:", c.prefixNotation ()
   
   print "\n\nImpossible condition:", GCimpossible.prefixNotation ()





reply via email to

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