commit-gnue
[Top][All Lists]
Advanced

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

r5776 - in trunk: gnue-common/src/datasources gnue-common/src/datasource


From: jcater
Subject: r5776 - in trunk: gnue-common/src/datasources gnue-common/src/datasources/drivers/DBSIG2 gnue-common/src/formatting/masks gnue-forms/src/GFObjects gnue-reports/samples/foobulations
Date: Mon, 3 May 2004 19:39:52 -0500 (CDT)

Author: jcater
Date: 2004-05-03 19:39:51 -0500 (Mon, 03 May 2004)
New Revision: 5776

Added:
   trunk/gnue-common/src/formatting/masks/__init__.py
   trunk/gnue-forms/src/GFObjects/GFMask.py
   trunk/gnue-reports/samples/foobulations/monthly-sql.grd
Modified:
   trunk/gnue-common/src/datasources/Exceptions.py
   trunk/gnue-common/src/datasources/GDataSource.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
   trunk/gnue-common/src/formatting/masks/Masks.py
Log:
Added basic <datasource type="sql"> support; some other mask stuff too.



Modified: trunk/gnue-common/src/datasources/Exceptions.py
===================================================================
--- trunk/gnue-common/src/datasources/Exceptions.py     2004-05-03 23:47:00 UTC 
(rev 5775)
+++ trunk/gnue-common/src/datasources/Exceptions.py     2004-05-04 00:39:51 UTC 
(rev 5776)
@@ -78,3 +78,9 @@
   # writing Schema to datasource
   pass
 
+class InvalidDatasourceDefintion(Error):
+  # Raised when a <datasource> definition is
+  # incomplete or otherwise doesn't make sense
+  # (e.g., a <datasource type="sql"> without a
+  # <sql> section.
+  pass
\ No newline at end of file

Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py    2004-05-03 23:47:00 UTC 
(rev 5775)
+++ trunk/gnue-common/src/datasources/GDataSource.py    2004-05-04 00:39:51 UTC 
(rev 5776)
@@ -79,14 +79,14 @@
                                         },
                               'getCondition':{'function':self.getCondition},
                               'setCondition':{'function':self.setCondition},
-                             'count' : {'function':self.triggerGetCount},
+                              'count' : {'function':self.triggerGetCount},
                               }
 
     self._triggerProperties = {'extensions':{'get':self.getExtensions,
                                            'direct':1},
-                               'recordCount':{'get':self.triggerGetCount,
-                                              'direct':1},
-                              }
+                                'recordCount':{'get':self.triggerGetCount,
+                                               'direct':1},
+                               }
 
   def __getattr__(self, attr):
     if self._dataObject and attr[1] != '_' and hasattr(self._dataObject,attr):
@@ -227,11 +227,24 @@
     except AttributeError:
       pass
 
+    hasRaw = False
     for child in self._children:
       if isinstance(child, GConditions.GCondition):
         dataObject._staticCondition = child
         break
+      elif isinstance(child, GSql):
+        dataObject._rawSQL = child
+        hasRaw = True
 
+
+    if self.type == "sql" and not hasRaw:
+      raise Exceptions.InvalidDatasourceDefintion, \
+        _("Datasource %s is sql-based, but has no <sql> definition.") % 
self.name
+    elif not self.type == "sql" and hasRaw:
+      raise Exceptions.InvalidDatasourceDefintion, \
+        _("Datasource %s is not sql-based, but has a <sql> definition.") % 
self.name
+
+
     # Copy all attributes from XML to the dataObject
     tagAttributes = getXMLelements()['datasource']['Attributes']
     for attribute in tagAttributes.keys():
@@ -324,7 +337,7 @@
     self.setConnectionManager(self._topObject._connections)
     self.initialize()
     self.connect()
-    self.extensions = self._dataObject.triggerExtensions    
+    self.extensions = self._dataObject.triggerExtensions
 
   # TODO: Merged into GDataSource per the TODOs in reports and forms however
   # TODO: self._topObject._datasourceDictionary implies that the top object
@@ -448,11 +461,11 @@
   xmlElements = {
       'datasource': {
          'BaseClass': GDataSource,
-         'Importable': 1,
+         'Importable': True,
          'Attributes': {
             'name':        {
-               'Required': 1,
-               'Unique':   1,
+               'Required': True,
+               'Unique':   True,
                'Typecast': GTypecast.name },
             'type':        {
                'Typecast': GTypecast.name,
@@ -460,7 +473,7 @@
             'connection':    {
                'Typecast': GTypecast.name },
             'database':    {
-               'Typecast': GTypecast.name, 
+               'Typecast': GTypecast.name,
                'Deprecated': 'Use {connection} attribute instead' },
             'table':       {
                'Typecast': GTypecast.name },
@@ -469,10 +482,10 @@
                'Default':  5 },
             'prequery':    {
                'Typecast': GTypecast.boolean,
-               'Default':  0 },
+               'Default':  False },
             'distinct':    {
                'Typecast': GTypecast.boolean,
-               'Default':  0 },
+               'Default':  False },
             'order_by':    {
                'Typecast': GTypecast.text },
             'master':      {
@@ -491,11 +504,11 @@
          'BaseClass': GStaticSet,
 #  TODO: This should be replaced by a SingleInstanceInParentObject
 #        instead of SingleInstance (in the whole file)
-#         'SingleInstance': 1,
+#         'SingleInstance': True,
          'Attributes': {
             'fields':        {
                'Typecast': GTypecast.text,
-               'Required': 1 } },
+               'Required': True } },
          'ParentTags': ('datasource',) },
       'staticsetrow': {
          'BaseClass': GStaticSetRow,
@@ -505,37 +518,41 @@
          'Attributes': {
             'name':        {
                'Typecast': GTypecast.text,
-               'Required': 1 },
+               'Required': True },
             'value':        {
                'Typecast': GTypecast.text,
-               'Required': 1 } },
+               'Required': True } },
          'ParentTags': ('staticsetrow',) },
+      'sql': {
+         'BaseClass': GSql,
+         'MixedContent': True,
+         'ParentTags': ('datasource',) },
       'connection': {
          'BaseClass': GConnection,
          'Attributes': {
             'name': {
-               'Required': 1,
-               'Unique': 1,
+               'Required': True,
+               'Unique': True,
                'Typecast': GTypecast.name,
                'Description': 'TODO' },
             'provider': {
-               'Required': 1,
+               'Required': True,
                'Typecast': GTypecast.name,
                'Description': 'TODO' },
             'dbname': {
-               'Required': 0,
+               'Required': False,
                'Typecast': GTypecast.text,
                'Description': 'TODO' },
             'service': {
-               'Required': 0,
+               'Required': False,
                'Typecast': GTypecast.text,
                'Description': 'TODO' },
             'comment': {
-               'Required': 0,
+               'Required': False,
                'Typecast': GTypecast.text,
                'Description': 'TODO' },
             'host': {
-               'Required': 0,
+               'Required': False,
                'Typecast': GTypecast.text,
                'Description': 'TODO' } },
          'ParentTags': None,
@@ -562,25 +579,25 @@
 #
 def DataSourceWrapper(connections=None, fields=(), attributes={}, init=1, 
unicodeMode=0):
   source = _DataSourceWrapper()
-  
-  if connections: 
+
+  if connections:
     source.setConnectionManager(connections)
-  
-  if init: 
+
+  if init:
     source.buildAndInitObject(**attributes)
-  else: 
+  else:
     source.buildObject(**attributes)
-    
-  if fields: 
+
+  if fields:
     source.referenceFields(fields)
-  
+
   return source
-  
-  
-class _DataSourceWrapper(GDataSource): 
-  def __init__(self, *args, **parms): 
+
+
+class _DataSourceWrapper(GDataSource):
+  def __init__(self, *args, **parms):
     GDataSource.__init__(self, *args, **parms)
     self._datasourceDictionary={}
     self._toplevelParent = self._type
-    
 
+

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py      
2004-05-03 23:47:00 UTC (rev 5775)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py      
2004-05-04 00:39:51 UTC (rev 5776)
@@ -175,7 +175,8 @@
     self._primaryIdChecked = 1
 
 
-  def _createResultSet(self, conditions={}, readOnly=0, 
masterRecordSet=None,sql=""):
+  def _createResultSet(self, conditions={}, readOnly=0,
+                       masterRecordSet=None,sql=""):
 
     # Used by drivers with a unique id (like rowid)
     if not self._primaryIdChecked: self._checkForPrimaryId()
@@ -188,8 +189,9 @@
       # pull a record count
       if self._strictQueryCount:
         recordCount = cursor.rowcount
-        #disable the count query and see if anyone screams
+        #disable the count query and see if anyone screams.
         #recordCount = self._getQueryCount(conditions,sql)
+        #  ARGH!!!! Oh, the agony... the agony....
 
     except self._DatabaseError, err:
       raise Exceptions.ConnectionError, err
@@ -355,8 +357,16 @@
 #
 #
 class DataObject_SQL(DataObject):
-  def _buildQuery(self, conditions={}):
-    # Obviously, this is in a pre-alpha state :)
-    return "select zipcode, city, state from zipcode order by zipcode desc"
 
+  # Set by GDataSource
+  # (GDataSource.GSql instance)
+  _rawSQL = None
 
+  def _buildQuery(self, conditions={}, forDetail=None, additionalSQL=""):
+    try:
+      sql= self.__sql
+    except AttributeError:
+      sql = self.__sql = self._rawSQL.getChildrenAsContent()
+    return sql
+
+

Modified: trunk/gnue-common/src/formatting/masks/Masks.py
===================================================================
--- trunk/gnue-common/src/formatting/masks/Masks.py     2004-05-03 23:47:00 UTC 
(rev 5775)
+++ trunk/gnue-common/src/formatting/masks/Masks.py     2004-05-04 00:39:51 UTC 
(rev 5776)
@@ -47,7 +47,7 @@
     self._inputMaskMap = {}
     self._maskMap = {}
 
-  def getInputMask(self, mask, numeric=False, date=False):
+  def getInputMask(self, mask, style="default", numeric=False, date=False):
     key = (numeric, date, mask)
     try:
       handler = self._inputMaskMap[key]
@@ -57,16 +57,26 @@
       handler = self._inputMaskMap[key] = _InputMask(mask, numeric, date)
     return handler
 
-  def getFormatMask(self, mask):
+  def getFormatMask(self, mask, style="default", ):
     try:
-      handler = self._inputMaskMap[mask]
+      handler = self._maskMap[mask]
       gDebug(5,'Reusing existing mask for %s' % mask)
     except KeyError:
       gDebug(5,'Creating mask handler for %s' % mask)
-      handler = self._inputMaskMap[mask] = None  #MaskParser(mask, numeric, 
date)
+      handler = self._maskMap[mask] = None
     return handler
 
+  def getValidationMask(self, mask, style="default", ):
+    try:
+      handler = self._maskMap[mask]
+      gDebug(5,'Reusing existing mask for %s' % mask)
+    except KeyError:
+      gDebug(5,'Creating mask handler for %s' % mask)
+      handler = self._maskMap[mask] = None
+    return handler
 
+
 library = MaskLibrary()
 InputMask = library.getInputMask
 FormatMask = library.getFormatMask
+ValidationMask = library.getValidationMask
\ No newline at end of file

Added: trunk/gnue-common/src/formatting/masks/__init__.py
===================================================================
--- trunk/gnue-common/src/formatting/masks/__init__.py  2004-05-03 23:47:00 UTC 
(rev 5775)
+++ trunk/gnue-common/src/formatting/masks/__init__.py  2004-05-04 00:39:51 UTC 
(rev 5776)
@@ -0,0 +1 @@
+from Masks import *
\ No newline at end of file

Added: trunk/gnue-forms/src/GFObjects/GFMask.py
===================================================================

Added: trunk/gnue-reports/samples/foobulations/monthly-sql.grd
===================================================================
--- trunk/gnue-reports/samples/foobulations/monthly-sql.grd     2004-05-03 
23:47:00 UTC (rev 5775)
+++ trunk/gnue-reports/samples/foobulations/monthly-sql.grd     2004-05-04 
00:39:51 UTC (rev 5776)
@@ -0,0 +1,90 @@
+<?xml version="1.0"?>
+<report>
+  <trigger name="Trigger_A" type="On-Startup">
+     print "Can you feel that GNUe-Common love?"
+  </trigger>
+  <trigger name="Trigger_B" type="On-Exit">
+     print "Oh yeah.....I can feel it"
+  </trigger>
+
+  <parameters>
+     <parameter name="subtitle" description="Report Subtitle"
+                default="Subtitle Not Provided"/>
+     <parameter name="startdate" description="Starting Date"
+                default="Subtitle Not Provided"/>
+     <parameter name="enddate" description="Ending Date"
+                default="04/30/02"/>
+  </parameters>
+
+  <sources>
+   <datasource database="gnue" name="dtsFoo" type="sql">
+     <sql><![CDATA[
+
+       select * from foobulations
+
+     ]]></sql>
+   </datasource>
+  </sources>
+
+  <layout xmlns:out="GNUe:Reports:SimpleTabulation">
+   <out:report>
+
+    <out:reportTitle>Monthly Accounting Foobulation Report</out:reportTitle>
+
+    <out:section break="page">
+      <out:sectionTitle><param name="subtitle"/></out:sectionTitle>
+      <out:table width="100%">
+        <out:tablehead>
+          <out:colhead width="30">Name</out:colhead>
+          <out:colhead width="22" align="center">Date</out:colhead>
+          <out:colhead width="10" align="right">Foobs</out:colhead>
+        </out:tablehead>
+
+        <section source="dtsFoo" name="nameBreak">
+           <trigger name="foo1" type="pre-section">
+             print "entering nameBreak"
+           </trigger>
+           <trigger name="foo1" type="post-section">
+             print "exiting nameBreak"
+           </trigger>
+           <section name="details">
+             <trigger name="foo1" type="pre-section">
+               print "entering details"
+             </trigger>
+             <trigger name="foo1" type="post-section">
+               print "exiting details"
+             </trigger>
+             <out:row>
+                <firstrow><out:col><field name="name" 
section="nameBreak"/></out:col></firstrow>
+                <notfirstrow><out:col/></notfirstrow>
+                <out:col align="center"><field name="foodate" 
format="%m/%d/%Y"/></out:col>
+                <out:col align="right"><field name="foobs"/></out:col>
+            </out:row>
+          </section>
+          <out:row type="subtotal" level="2">
+            <out:col/>
+            <out:col align="right">Total for <field name="name"/></out:col>
+            <out:col align="right"><summ function="sum" section="details" 
field="foobs"/></out:col>
+          </out:row>
+          <default>
+            <out:row>
+              <out:col>(No results to display)</out:col>
+              <out:col/>
+              <out:col/>
+            </out:row>
+          </default>
+        </section>
+        <out:row type="subtotal" level="1">
+          <out:col/>
+          <out:col align="right">Grand Total</out:col>
+          <out:col align="right"><summ function="sum" section="nameBreak" 
field="foobs"/></out:col>
+        </out:row>
+
+
+      </out:table>
+    </out:section>
+
+   </out:report>
+
+  </layout>
+</report>





reply via email to

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